Skip to content

Instantly share code, notes, and snippets.

@JeppeSigaard
Created September 6, 2016 11:44
Show Gist options
  • Save JeppeSigaard/dca43ffdc4babaeee31b650c3e008d50 to your computer and use it in GitHub Desktop.
Save JeppeSigaard/dca43ffdc4babaeee31b650c3e008d50 to your computer and use it in GitHub Desktop.
<?php
/* --------------------------------------- */
// Show page templates as states in page list
add_filter( 'display_post_states', 'prfx_template_state', 10, 2 );
function prfx_template_state($post_states, $post){
// Fetch array of templates, returning Display name => slug, which is odd, but useful.
$templates = get_page_templates();
// Let's only run on pages for now
if('page' === get_post_type($post->ID)){
// Loop through and apply
foreach($templates as $name => $slug){
if($slug === get_page_template_slug($post->ID)){
$post_states[] = $name;
}
}
}
// Return the new list of states, ez!
return $post_states;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment