is_page_template( string|array $template = '' )
Whether currently in a page template.
Description
This template tag allows you to determine if you are in a page template. You can optionally provide a template name or array of template names and then the check will be specific to that template.
Parameters
- $template
-
(Optional) The specific template name or array of templates to match.
Default value: ''
Return
(bool) True on success, false on failure.
Source
File: wp-includes/post-template.php
function is_page_template( $template = '' ) {
if ( ! is_singular() ) {
return false;
}
$page_template = get_page_template_slug( get_queried_object_id() );
if ( empty( $template ) )
return (bool) $page_template;
if ( $template == $page_template )
return true;
if ( is_array( $template ) ) {
if ( ( in_array( 'default', $template, true ) && ! $page_template )
|| in_array( $page_template, $template, true )
) {
return true;
}
}
return ( 'default' === $template && ! $page_template );
}
Changelog
Version | Description |
---|---|
WP-4.7.0 | Now works with any post type, not just pages. |
WP-4.2.0 | The $template parameter was changed to also accept an array of page templates. |
WP-2.5.0 | Introduced. |