How can I add a 'Page Template' column to the Dashboard, so that viewing 'All cpt_name' shows which template is used.

up vote 1 down vote accepted
<?php
// add new column to the columns array
function wpse267793_columns($columns) {
    // Column name
    $columns['template'] = 'Template file';
    return $columns;
}

function wpse267793_show_template_columns($name, $post_id) {
    // get template file name from post meta
    $template = get_post_meta($post_id, '_wp_page_template', true);
    echo $template;
}

// change 'CPT' to the relevant custom post type
add_filter('manage_CPT_posts_columns', 'wpse267793_columns');

add_action('manage_CPT_posts_custom_column',  'wpse267793_show_template_columns', 10, 2);
  • @ Max Yudin ... Thanks. I delayed responding because adding this column also adds the template info to an additional column I'd added previously to show post ID, and I wanted to try to find a fix before posting here - but haven't yet been able to do so. – glvr May 24 '17 at 10:53
  • So, what's the question if you can add a column by yourself? – Max Yudin May 24 '17 at 11:20
  • @ Max Yudin ... I didn't know about _wp_page_template. – glvr May 24 '17 at 11:34
  • And, likely, you were banned by Google. – Max Yudin May 24 '17 at 11:39
  • @ Max Yudin ... if you don't know what to search for, it's difficult to find answers. And, as always, I searched before posting here. – glvr May 24 '17 at 15:06

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.