W3cubDocs

/WordPress

WP_Block_Templates_Registry::get_by_slug( string $template_slug ): WP_Block_Template|null

Retrieves a registered template by its slug.

Parameters

$template_slugstringrequired
Slug of the template.

Return

WP_Block_Template|null The registered template, or null if it is not registered.

Source

public function get_by_slug( $template_slug ) {
	$all_templates = $this->get_all_registered();

	if ( ! $all_templates ) {
		return null;
	}

	foreach ( $all_templates as $template ) {
		if ( $template->slug === $template_slug ) {
			return $template;
		}
	}

	return null;
}

Changelog

Version Description
6.7.0 Introduced.

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