W3cubDocs

/WordPress

register_block_template( string $template_name, array|string $args = array() ): WP_Block_Template|WP_Error

Register a block template.

Parameters

$template_namestringrequired
Template name in the form of plugin_uri//template_name.
$argsarray|stringoptional
  • title string
    Optional. Title of the template as it will be shown in the Site Editor and other UI elements.
  • description string
    Optional. Description of the template as it will be shown in the Site Editor.
  • content string
    Optional. Default content of the template that will be used when the template is rendered or edited in the editor.
  • post_types string[]
    Optional. Array of post types to which the template should be available.
  • plugin string
    Optional. Slug of the plugin that registers the template.

Default:array()

Return

WP_Block_Template|WP_Error The registered template object on success, WP_Error object on failure.

Source

function register_block_template( $template_name, $args = array() ) {
	return WP_Block_Templates_Registry::get_instance()->register( $template_name, $args );
}

Changelog

Version Description
6.7.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/register_block_template