WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get page templates

Description

This function returns the available page templates in the currently active theme. It searches all the current theme's template files for the commented Template Name: name of template. See also get_current_theme() and the wp_get_theme()->get_page_templates() method of the WP_Theme class.

Usage

 <?php $templates get_page_templates(); ?> 

Parameters

None.

Return Value

(array) 
Where key is the name of the template and value is the filename.

Examples

Output a list of available templates

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

<?php 
   $templates = get_page_templates();
   foreach ( $templates as $template_name => $template_filename ) {
       echo "$template_name ($template_filename)<br />";
   }
?>
<?php print_r(get_page_templates());?>
Array
(
    [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
)

Source File

get_page_templates() is located in wp-admin/includes/theme.php.

Related

get_stylesheet_directory, get_current_theme

See also index of Function Reference and index of Template Tags.