is_page_template

The timeline below displays how wordpress function is_page_template has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * Determines whether the current post uses a page template.
 *
 * 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 {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @since 2.5.0
 * @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.
 *
 * @param string|string[] $template The specific template filename or array of templates to match.
 * @return bool True on success, false on failure.
 */
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;
}

WordPress Version: 5.7

/**
 * Determines 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 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 {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @since 2.5.0
 * @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.
 *
 * @param string|string[] $template The specific template filename or array of templates to match.
 * @return bool True on success, false on failure.
 */
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;
}

WordPress Version: 5.4

/**
 * Determines 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 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 {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @since 2.5.0
 * @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.
 *
 * @param string|array $template The specific template filename or array of templates to match.
 * @return bool True on success, false on failure.
 */
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;
}

WordPress Version: 5.1

/**
 * Determines 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.
 *
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
 * Conditional Tags} article in the Theme Developer Handbook.
 *
 * @since 2.5.0
 * @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.
 *
 * @param string|array $template The specific template name or array of templates to match.
 * @return bool True on success, false on failure.
 */
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;
}

WordPress Version: 5.0

/**
 * Determines 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.
 * 
 * For more information on this and similar theme functions, check out
 * the {@link https://developer.wordpress.org/themes/basics/conditional-tags/ 
 * Conditional Tags} article in the Theme Developer Handbook.
 * 
 * @since 2.5.0
 * @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.
 *
 * @param string|array $template The specific template name or array of templates to match.
 * @return bool True on success, false on failure.
 */
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;
}

WordPress Version: 7.1

/**
 * 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 2.5.0
 * @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.
 *
 * @param string|array $template The specific template name or array of templates to match.
 * @return bool True on success, false on failure.
 */
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;
}

WordPress Version: 4.7

/**
 * 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 2.5.0
 * @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.
 *
 * @param string|array $template The specific template name or array of templates to match.
 * @return bool True on success, false on failure.
 */
function is_page_template($template = '')
{
    $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;
}

WordPress Version: 4.3

/**
 * 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 2.5.0
 * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
 *
 * @param string|array $template The specific template name or array of templates to match.
 * @return bool True on success, false on failure.
 */
function is_page_template($template = '')
{
    if (!is_page()) {
        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;
}

WordPress Version: 4.2

/**
 * 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 2.5.0
 * @since 4.2.0 The `$template` parameter was changed to also accept an array of page templates.
 *
 * @param string|array $template The specific template name or array of templates to match.
 * @return bool True on success, false on failure.
 */
function is_page_template($template = '')
{
    if (!is_page()) {
        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;
        }
    }
    if ('default' == $template && !$page_template) {
        return true;
    }
    return false;
}

WordPress Version: 4.1

/**
 * 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 and then the check will be
 * specific to that template.
 *
 * @since 2.5.0
 *
 * @param string $template The specific template name if specific matching is required.
 * @return bool True on success, false on failure.
 */
function is_page_template($template = '')
{
    if (!is_page()) {
        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 ('default' == $template && !$page_template) {
        return true;
    }
    return false;
}

WordPress Version: 3.7

/**
 * 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 and then the check will be
 * specific to that template.
 *
 * @since 2.5.0
 * @uses $wp_query
 *
 * @param string $template The specific template name if specific matching is required.
 * @return bool True on success, false on failure.
 */
function is_page_template($template = '')
{
    if (!is_page()) {
        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 ('default' == $template && !$page_template) {
        return true;
    }
    return false;
}