-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Closed
Copy link
Labels
[Feature] Block hooks[Feature] Templates APIRelated to API powering block template functionality in the Site EditorRelated to API powering block template functionality in the Site Editor[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
Description
Apparently, block hooks are not being applied to templates registered by plugins using the Template registration API.
Step-by-step reproduction instructions
- Install the Dynamic Copyright Date plugin, to have a block as an example.
- Add this snippet to your site that (1) creates a template for posts, where only the Separator block is rendered and (2) hooks the Dynamic Copyright Date block to the Separator block:
register_block_template(
'my-plugin//plugin-template',
array(
'title' => 'Test Template',
'description' => 'This is a test template',
'content' => '<!-- wp:separator {className":"is-style-dots"} --><hr class="wp-block-separator has-alpha-channel-opacity is-style-dots"/><!-- /wp:separator -->',
)
);
add_action(
'single_template_hierarchy',
function () {
return array( 'plugin-template' );
}
);
add_filter(
'hooked_block_types',
function ( $hooked_block_types, $relative_position, $anchor_block_type, $context ) {
if ( 'after' === $relative_position && 'core/separator' === $anchor_block_type ) {
$hooked_block_types[] = 'dynamic-copyright-date/copyright-date-block';
}
return $hooked_block_types;
},
10,
4
);- Create a new page and add the Separator block.
- Now, in the frontend, visit a page (using the theme template) and a post (using the plugin template):
- Notice the page correctly applies the block hook (adds the Dynamic Copyright Date block after the Separator block), while the post, doesn't.
Screenshots, screen recording, code snippet
| Page | Post |
|---|---|
![]() |
![]() |
Environment info
- WordPress 6.8.2.
- Plugins: Code Snippets and Dynamic Copyright Date Block.
- Themes used for testing: TT4 and TT5.
Please confirm that you have searched existing issues in the repo.
- Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- Yes
Please confirm which theme type you used for testing.
- Block
- Classic
- Hybrid (e.g. classic with theme.json)
- Not sure
Adi-ty
Metadata
Metadata
Assignees
Labels
[Feature] Block hooks[Feature] Templates APIRelated to API powering block template functionality in the Site EditorRelated to API powering block template functionality in the Site Editor[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended

