En función.php
function register_custom_patterns() {
register_block_pattern(
'twentytwentyfive/asif', // The pattern slug
array(
'title' => __( 'Test Pattern', 'twentytwentyfive' ),
'description' => __( 'A custom test pattern for the theme.', 'twentytwentyfive' ),
'content' => file_get_contents( get_template_directory_uri() . '/patterns/asif.php'), // Path to your custom PHP file
)
);
}
add_action( 'init', 'register_custom_patterns' );
Ubicación del archivo asif.php
C:\xampp\htdocs\asif_wp\wp-content\themes\twentytwentyfive\patterns\asif.php
código asif.php
function asif() {
echo "Working!";
}
add_action( 'init', 'asif' );
Después de cargar Patrón de prueba en el tema
Error:
Fatal error: Uncaught Error: Call to undefined function add_action() in C:\xampp\htdocs\asif_wp\wp-content\themes\twentytwentyfive\patterns\asif.php:6
Stack trace:
#0 {main}
thrown in C:\xampp\htdocs\asif_wp\wp-content\themes\twentytwentyfive\patterns\asif.php on line 6
Luego edité asif.php
Resultado:
El navegador se está cargando (esperando) y pasando por un bucle infinito y al final mi computadora se cuelga