W3cubDocs

/WordPress

get_page_templates( WP_Post|null $post = null, string $post_type = 'page' )

Get the Page Templates available in this theme

Description

Parameters

$post

(WP_Post|null) (Optional) The post being edited, provided for context.

Default value: null

$post_type

(string) (Optional) Post type to get the templates for.

Default value: 'page'

Return

(array) Key is the template name, value is the filename of the template

Source

File: wp-admin/includes/theme.php

function get_page_templates( $post = null, $post_type = 'page' ) {
	return array_flip( wp_get_theme()->get_page_templates( $post, $post_type ) );
}

Changelog

Version Description
4.7.0 Added the $post_type parameter.
1.5.0 Introduced.

© 2003–2019 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_page_templates