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

In this article

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

VersionDescription
6.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.