wordpress snippets last updated   : August 18, 2014
we now have 638 snippets

Custom column with currently active page template

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will add a column to your admin pages showing which wordpress page template currently in use.

( example screenshot )
snippet :  PHPcopy
add_filter( 'manage_pages_columns', 'page_column_views' );
add_action( 'manage_pages_custom_column', 'page_custom_column_views', 5, 2 );
function page_column_views( $defaults )
{
   $defaults['page-layout'] = __('Template');
   return $defaults;
}
function page_custom_column_views( $column_name, $id )
{
   if ( $column_name === 'page-layout' ) {
       $set_template = get_post_meta( get_the_ID(), '_wp_page_template', true );
       if ( $set_template == 'default' ) {
           echo 'Default';
       }
       $templates = get_page_templates();
       ksort( $templates );
       foreach ( array_keys( $templates ) as $template ) :
           if ( $set_template == $templates[$template] ) echo $template;
       endforeach;
   }
}

Did you like this post? If so please share it with your friends. Thanks!

  • Ru

    This works great, but I am really struggling with sorting the column. I managed to make the column sortable. eg. I can click on the column title, and it definitely does something, but I think it is just reversing the natural order upside down :(, and what I need is to sort alphabetically by the template name.

jqsnipp.com | we just launched jquery snippets website