This template tag allows you to determine if you are in a page template. You can optionally provide a template filename or array of template filenames and then the check will be specific to that template.
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
Due to certain global variables being overwritten during The Loop is_page_template() will not work. In order to use it after The Loop you must call wp_reset_query() after The Loop.
Alternative
Since the page template slug is stored inside the post_meta for any post that has been assigned to a page template, it is possible to directly query the post_meta to see whether any given page has been assigned a page template. This is the method that is_page_template() uses internally.
The function get_page_template_slug( $post_id ) will return the slug of the currently assigned page template (or an empty string if no template has been assigned – or false if the $post_id does not correspond to an actual page). You can easily use this anywhere (in The Loop, or outside) to determine whether any page has been assigned a page template.
// in the loop:
if ( get_page_template_slug( get_the_ID() ) ){
// Yep, this page has a page template
}
// anywhere:
if ( get_page_template_slug( $some_post_ID ) ){
// Uh-huh.
}
Is Page Template ‘about’ being used? Note that unlike with other conditionals, if you want to specify a particular Page Template, you need to use the filename, such as about.php or my_page_template.php.
if ( is_page_template( 'about.php' ) ) {
// about.php is used
} else {
// about.php is not used
}
You can also specify multiple templates by passing an array of template names.
if ( is_page_template( array( 'template-full-width.php', 'template-product-offers.php' ) ) ) {
// Do Something here if either of the above templates are being used
}
else {
// Else do this
}
If the post is assigned to a HTML template inside the /templates/ folder, the $template parameter should be the template filename without the .html suffix.
if ( is_page_template( 'page-no-title' ) ) { // templates/page-no-title.html is used } else { // templates/page-no-title.html is not used }
If the post is assigned to a HTML template inside the /templates/ folder, the $template parameter should be the template filename without the .html suffix.
if ( is_page_template( 'page-no-title' ) ) {
// templates/page-no-title.html is used
} else {
// templates/page-no-title.html is not used
}
You must log in before being able to contribute a note or feedback.
Is Page Template ‘about’ being used? Note that unlike with other conditionals, if you want to specify a particular Page Template, you need to use the filename, such as
about.php
ormy_page_template.php
.If your page template resides within a directory, you can use something like this:
This can be useful if you’re using multiple page templates and want to keep your files organised.
You can also specify multiple templates by passing an array of template names.
/templates/
folder, the$template
parameter should be the template filename without the.html
suffix.If the post is assigned to a HTML template inside the
/templates/
folder, the$template
parameter should be the template filename without the.html
suffix.