wppaste
WordPress

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

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.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 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 source
4.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.