WordPress.org

Ready to get started?Download WordPress

Codex

Attention 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().

Usage

 <?php $templates get_page_templates(); ?> 

Parameters

None.

Return Value

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

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 />";
   }
?>
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.