Skip to content

Instantly share code, notes, and snippets.

@soderlind
Last active January 10, 2017 20:26
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 soderlind/107c5c382ecbd420599fe27052e769c0 to your computer and use it in GitHub Desktop.
Save soderlind/107c5c382ecbd420599fe27052e769c0 to your computer and use it in GitHub Desktop.
Get WordPress post template data
<?php
$current_theme = wp_get_theme(); // get WP_Theme object
if ( count( $post_templates = $current_theme->get_post_templates() ) ) { // https://developer.wordpress.org/reference/classes/wp_theme/get_post_templates/
printf( '<pre>%s</pre>', print_r( $post_templates, true ) );
}
/*
Prints:
Array
(
[game] => Array // Template Post Type
(
[template-game-review.php] => Game Review // file name => Template Name
)
)
*/
<?php
/*
Template Name: Game Review
Template Post Type: game
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment