Skip to content

Instantly share code, notes, and snippets.

@keesiemeijer
Last active February 5, 2016 10:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keesiemeijer/1770ed2dde9041093940 to your computer and use it in GitHub Desktop.
Save keesiemeijer/1770ed2dde9041093940 to your computer and use it in GitHub Desktop.
get all page templates
<?php
$post_templates = array();
$theme = wp_get_theme();
$files = (array) $theme->get_files( 'php', 1 );
foreach ( $files as $file => $full_path ) {
$headers = get_file_data( $full_path, array( 'Template Name' => 'Template Name' ) );
if ( empty( $headers['Template Name'] ) ) {
continue;
}
$post_templates[ $file ] = $headers['Template Name'];
}
echo '<pre>';
print_r( $post_templates );
echo '</pre>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment