is_page_template

Whether currently in a page template.

Description

is_page_template( (string) $template = '' ); 

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 (1)

0. $template — Optional. (string) => ''
The specific template name or array of templates to match.

Usage

  1. if ( !function_exists( 'is_page_template' ) ) { 
  2. require_once ABSPATH . WPINC . '/post-template.php'; 
  3.  
  4. // The specific template name or array of templates to match. 
  5. $template = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = is_page_template($template); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post-template.php  
  1. function is_page_template( $template = '' ) { 
  2. if ( ! is_singular() ) { 
  3. return false; 
  4.  
  5.  
  6. if ( empty( $template ) ) 
  7. return (bool) $page_template; 
  8.  
  9. if ( $template == $page_template ) 
  10. return true; 
  11.  
  12. if ( is_array( $template ) ) { 
  13. if ( ( in_array( 'default', $template, true ) && ! $page_template ) 
  14. || in_array( $page_template, $template, true ) 
  15. ) { 
  16. return true; 
  17.  
  18. return ( 'default' === $template && ! $page_template );