is_page_template()WP 2.5.0

Checks if the template file is used to display the current page. You can specify the name of the file.

You can specify the name of a specific file to check. For example about.php. If this file is used to generate the page, the function will return true.

Does not work inside the WordPress loop.

If the name of the template file is specified and the file is located in a nested folder, then the name of the nested folder must also be specified:

is_page_template( 'templates/about.php' )

// sometimes (depends on how you specify templates)
is_page_template( '/templates/about.php' )
1 time — 0.00016 sec (fast) | 50000 times — 2.95 sec (fast)

No Hooks.

Returns

true|false.

Usage

if( is_page_template( $template ) ){
	// ...
}
$template(string/array)
The name of the template file (with extension). Since version 4.2, you can specify multiple names in an array.
Default: ''

Examples

1

#1 Check whether the file about.php is used to display the page

If the template page "about" is displayed, we can determine it by the file that is responsible for displaying the content of this page.

Suppose we have a separate template file about.php for this page. Then the check code will look like this:

if ( is_page_template('about.php') ) {
	// this will work if the file 'about.php' is used
}
else {
	// this will work if 'about.php' is not used
}
0

#2 Check if the page has a separate template

This example shows how to check if the current static page has a separate template file to display its content:

if ( is_page_template() ) {
	// a separate template is used
}
else {
	// normal output
}
0

#3 A number of template names to check out

You can also specify multiple templates by passing an array of template names.

if( is_page_template( [ 'about.php', 'sitemap.php' ] ) ) {
	// one of the templates is used
}
else {
	// normal output, no templates
}
0

#4 Template from sub-directory

If your page template resides within a directory, you can use something like this:

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

This can be useful if you’re using multiple page templates and want to keep your files organised.

Changelog

Since 2.5.0 Introduced.
Since 4.2.0 The $template parameter was changed to also accept an array of page templates.
Since 4.7.0 Now works with any post type, not just pages.

is_page_template() code WP 6.8.3

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 );
}