Retrieves a registered template by its slug.
$template_slugstringrequired
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;
}
| 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