WordPress at a glance

is_page_template() WP 1.0

Whether currently in a page 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.

  • 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.
✈ 1 time = 0.00016s = fast | 50000 times = 2.95s = fast

No Hooks.

Return

true/false. True on success, false on failure.

Usage

is_page_template( $template );
$template(string/array)
The specific template name or array of templates to match.
Default: ''

Code of is_page_template: wp-includes/post-template.php VER 4.9.8

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

Related Functions

From tag: Conditional tags (page type and request)

More from tag: Conditional tags (all)

More from category: Theme files connection

More from Template Tags: Main Functions

No comments
    Hello, !     Log In . Register