WP_Block_Templates_Registry::get_by_slug()
Retrieves a registered template by its slug.
Method of the class: WP_Block_Templates_Registry{}
No Hooks.
Return
WP_Block_Template|null
. The registered template, or null if it is not registered.
Usage
$WP_Block_Templates_Registry = new WP_Block_Templates_Registry(); $WP_Block_Templates_Registry->get_by_slug( $template_slug );
- $template_slug(string) (required)
- Slug of the template.
Changelog
Since 6.7.0 | Introduced. |
WP_Block_Templates_Registry::get_by_slug() WP Block Templates Registry::get by slug code WP 6.7.2
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; }