I need to modify the default markup generated using the render_block_core_post_template
function located inside wp-includes > blocks > post-template.php.
I don't see any other way of modifying the markup so i can insert a custom field.
Is it possible to override this core template via a theme or plugin? If so, where to start.
function register_block_core_post_template() {
register_block_type_from_metadata(
__DIR__ . '/post-template',
array(
'render_callback' => 'render_block_core_post_template',
'skip_inner_blocks' => true,
)
);
}
add_action( 'init', 'register_block_core_post_template' );
I need to modify the default markup generated using the render_block_core_post_template
function located inside wp-includes > blocks > post-template.php.
I don't see any other way of modifying the markup so i can insert a custom field.
Is it possible to override this core template via a theme or plugin? If so, where to start.
function register_block_core_post_template() {
register_block_type_from_metadata(
__DIR__ . '/post-template',
array(
'render_callback' => 'render_block_core_post_template',
'skip_inner_blocks' => true,
)
);
}
add_action( 'init', 'register_block_core_post_template' );
To insert a custom field:
I recommend using the Meta Field Block plugin developed just for this purpose
To alter core/post-template
's DOM with PHP
Add a filter to render_block action e.g. in functions.php
// Replace post-template block with custom DOM
add_filter( 'render_block', 'MyPostTemplate' , 10, 2 );
function MyPostTemplate( $block_content, $block )
{
// bypass if other block
if ( 'core/post-template' !== $block['blockName'] ) return $block_content;
// do something with $block_content (here we prepend a paragraph to each listed entry)
$block_content=str_replace("<li ", "<p>Hello world!</p><li ", $block_content);
return $block_content;
}