get_page_template_slug

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

WordPress Version: 6.1

/**
 * Gets the specific template filename for a given post.
 *
 * @since 3.4.0
 * @since 4.7.0 Now works with any post type, not just pages.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string|false Page template filename. Returns an empty string when the default page template
 *                      is in use. Returns false if the post does not exist.
 */
function get_page_template_slug($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $template = get_post_meta($post->ID, '_wp_page_template', true);
    if (!$template || 'default' === $template) {
        return '';
    }
    return $template;
}

WordPress Version: 5.5

/**
 * Get the specific template filename for a given post.
 *
 * @since 3.4.0
 * @since 4.7.0 Now works with any post type, not just pages.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string|false Page template filename. Returns an empty string when the default page template
 *                      is in use. Returns false if the post does not exist.
 */
function get_page_template_slug($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $template = get_post_meta($post->ID, '_wp_page_template', true);
    if (!$template || 'default' === $template) {
        return '';
    }
    return $template;
}

WordPress Version: 5.4

/**
 * Get the specific template filename for a given post.
 *
 * @since 3.4.0
 * @since 4.7.0 Now works with any post type, not just pages.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string|false Page template filename. Returns an empty string when the default page template
 *                      is in use. Returns false if the post does not exist.
 */
function get_page_template_slug($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $template = get_post_meta($post->ID, '_wp_page_template', true);
    if (!$template || 'default' == $template) {
        return '';
    }
    return $template;
}

WordPress Version: 5.1

/**
 * Get the specific template name for a given post.
 *
 * @since 3.4.0
 * @since 4.7.0 Now works with any post type, not just pages.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string|false Page template filename. Returns an empty string when the default page template
 *  is in use. Returns false if the post does not exist.
 */
function get_page_template_slug($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $template = get_post_meta($post->ID, '_wp_page_template', true);
    if (!$template || 'default' == $template) {
        return '';
    }
    return $template;
}

WordPress Version: 4.7

/**
 * Get the specific template name for a given post.
 *
 * @since 3.4.0
 * @since 4.7.0 Now works with any post type, not just pages.
 *
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 * @return string|false Page template filename. Returns an empty string when the default page template
 * 	is in use. Returns false if the post does not exist.
 */
function get_page_template_slug($post = null)
{
    $post = get_post($post);
    if (!$post) {
        return false;
    }
    $template = get_post_meta($post->ID, '_wp_page_template', true);
    if (!$template || 'default' == $template) {
        return '';
    }
    return $template;
}

WordPress Version: 4.3

/**
 * Get the specific template name for a page.
 *
 * @since 3.4.0
 *
 * @param int $post_id Optional. The page ID to check. Defaults to the current post, when used in the loop.
 * @return string|false Page template filename. Returns an empty string when the default page template
 * 	is in use. Returns false if the post is not a page.
 */
function get_page_template_slug($post_id = null)
{
    $post = get_post($post_id);
    if (!$post || 'page' != $post->post_type) {
        return false;
    }
    $template = get_post_meta($post->ID, '_wp_page_template', true);
    if (!$template || 'default' == $template) {
        return '';
    }
    return $template;
}

WordPress Version: 3.7

/**
 * Get the specific template name for a page.
 *
 * @since 3.4.0
 *
 * @param int $post_id Optional. The page ID to check. Defaults to the current post, when used in the loop.
 * @return string|bool Page template filename. Returns an empty string when the default page template
 * 	is in use. Returns false if the post is not a page.
 */
function get_page_template_slug($post_id = null)
{
    $post = get_post($post_id);
    if (!$post || 'page' != $post->post_type) {
        return false;
    }
    $template = get_post_meta($post->ID, '_wp_page_template', true);
    if (!$template || 'default' == $template) {
        return '';
    }
    return $template;
}