Using WordPress ‘is_page_template()’ PHP function

The is_page_template() WordPress PHP function determines whether the current post uses a page template. You can provide a specific template filename or an array of template filenames to check if the current post is using one of those templates.

Usage

$is_using_template = is_page_template( 'about.php' );

Parameters

  • $template (string|string[]) – Optional. The specific template filename or array of templates to match. Default: ''

More information

See WordPress Developer Resources: is_page_template()

Examples

Check if a specific template is used

This example checks if the current post is using the about.php template.

if ( is_page_template( 'about.php' ) ) {
    // about.php is used
} else {
    // about.php is not used
}

Check if a template inside a directory is used

This example checks if the current post is using the page-about.php template inside the directory-name folder.

if ( is_page_template( 'directory-name/page-about.php' ) ) {
    // page-about.php is used
} else {
    // page-about.php is not used
}

Check if any of the specified templates are used

This example checks if the current post is using either template-full-width.php or template-product-offers.php templates.

if ( is_page_template( array( 'template-full-width.php', 'template-product-offers.php' ) ) ) {
    // Either of the above templates are being used
} else {
    // Neither of the above templates are being used
}

Check if any page template is used

This example checks if the current post is using any page template.

if ( is_page_template() ) {
    // A page template is being used
} else {
    // No page template is being used
}

Check if a specific template is NOT used

This example checks if the current post is NOT using the about.php template.

if ( !is_page_template( 'about.php' ) ) {
    // about.php is not used
} else {
    // about.php is used
}