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

Gets the page templates available in this theme.

Parameters Parameters


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

Default value: null


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

Default value: 'page'

Top ↑

Return Return

(string[]) Array of template file names keyed by the template header name.

Top ↑

More Information More Information

The function searches all the current theme’s template files for the commented “Template Name: name of template”. See also wp_get_theme() and the wp_get_theme()->get_page_templates() method of the WP_Theme class.

Top ↑

Source 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 ) );

Top ↑

Changelog Changelog

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

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Codex

    Output a list of available templates

    The following code snippet loops through the available page templates and outputs their template names and the filenames.

       $templates = get_page_templates();
       foreach ( $templates as $template_name => $template_filename ) {
           echo "$template_name ($template_filename)<br />";
    <?php print_r(get_page_templates());?>
        [Sidebar] => sidebar.php
        [Category] => category.php
        [Page] => page.php
        [Home] => home.php
        [Single] => single.php
        [Comments Popup] => comments-popup.php
        [Footer] => footer.php
        [Header] => header.php
        [Index] => index.php
        [Contact] => contact.php
        [Home-Intro] => home-intro.php
        [Sidebar Left] => sidebar-left.php
        [Sidebar Right] => sidebar-right.php
        [TOC Home] => page-client-toc.php
        [Search Form] => searchform.php
        [Main-Navbar] => main-navbar.php
        [Bookmarks] => page-bookmarks.php

You must log in before being able to contribute a note or feedback.