get_page_template_slug( int|WP_Post $post = null ): string|false
- Since
- 3.4.0, 4.7.0
- Source
wp-includes/post-template.php:1887
Gets the specific template filename for a given post.
Parameters
$postint|WP_Postoptional- Post ID or WP_Post object. Default is global $post.Default:
null
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.
Uses · 2
- get_post()Retrieves post data given a post ID or post object.
- get_post_meta()Retrieves a post meta field for the given post ID.
Used by · 10
- WP_REST_Posts_Controller::check_template()Checks whether the template is valid for the given post.
- WP_REST_Posts_Controller::prepare_item_for_response()Prepares a single post output for response.
- _WP_Editors::editor_settings()
- get_body_class()Retrieves an array of the class names for the body element.
- get_page_template()Retrieves path of page template in current or parent template.
- get_single_template()Retrieves path of single template in current or parent template. Applies to single Posts, single Attachments, and single custom post types.
- is_page_template()Determines whether the current post uses a page template.
- twentytwenty_body_classes()Adds conditional body classes.
- wp_get_post_content_block_attributes()Retrieves Post Content block attributes from the current post template.
- wp_xmlrpc_server::_prepare_page()Prepares page data for return in an XML-RPC object.
Source
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;}History
Introduced in 3.4.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
7.0.4
Parameter
$post retyped from int|WP_Post to int|WP_Post|null.verified against source4.7.0
Now works with any post type, not just pages.from the docblock
3.4.0
Introduced.from the docblock
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/post-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.