unregister_block_template()
Unregisters a block page template added through register_block_template().
Removes the template from the registry. It does not remove templates added by a theme or created by a user.
If the template is not registered, the function will trigger a notice about incorrect usage and return a template_not_registered error.
Use register_block_template() when you need to register a block template from a plugin.
No Hooks.
Returns
WP_Block_Template|WP_Error.
- WP_Block_Template — the template object removed from the registry.
- WP_Error — if the template is not registered.
Usage
unregister_block_template( $template_name );
- $template_name(string) (required)
The template name in the
plugin-slug//template-nameformat.Must exactly match the name passed to register_block_template().
Examples
#1 Unregister another plugin's template
Priority 20 lets the code run after the usual template registration on the init action at priority 10.
add_action( 'init', 'my_plugin_unregister_book_template', 20 );
function my_plugin_unregister_book_template() {
unregister_block_template( 'book-plugin//single-book' );
}Changelog
| Since 6.7.0 | Introduced. |
unregister_block_template() unregister block template code WP 7.1.2
function unregister_block_template( $template_name ) {
return WP_Block_Templates_Registry::get_instance()->unregister( $template_name );
}