Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
$10
Add Page Template column to Manage Pages screen
I have hunted for an answer online and cobbled together the below code - NOTE: the code obviously doesn't work, but hopefully gives an idea of what I am trying to achieve.
Thank you
function add_page_text_column($page_columns) {
$page_columns['page_template'] = "Page template";
return $page_columns;
}
add_action('manage_pages_columns', 'add_page_text_column');
function show_page_template_column($post){
global $post;
switch ($post) {
case 'column-page-template':
$page_template = get_post_meta($post_id, '_wp_page_template', true); // file name
$result = array_search($page_template, get_page_templates()); // get template nice name
echo $result;
break;
default:
break;
}
}
add_action('manage_pages_custom_column','show_page_template_column');
This question has been answered.
designbuildtest | 06/17/12 at 10:12pm
Edit
(3) Possible Answers Submitted...
See a chronological view of answers?
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
-

Last edited:
06/17/12
10:17pmNavjot Singh says:There is a plugin to do the job already. Here it is: Reveal Page Templates
- 06/17/12 10:52pm
designbuildtest says:Thanks Navjot. This plugin looks good, but I was hoping for a simple function to put in my functions.php file.
- 06/17/12 10:54pm
Navjot Singh says:Okay. Try this then?
function add_page_text_column($page_columns) {
$page_columns['page_template'] = "Page template";
return $page_columns;
}
add_action('manage_pages_columns', 'add_page_text_column');
function show_page_template_column($column_name, $post_id){
if( $column_name == 'page_template' ) {
$page_template = get_post_meta($post_id, '_wp_page_template', true); // file name
$templates = get_page_templates();
$result = array_search($page_template, $templates); // get template nice name
if( !$result )
echo ''.__('default').'';
echo $result;
}
}
add_action('manage_pages_custom_column','show_page_template_column',10,2); - 06/17/12 11:05pm
designbuildtest says:Works great Navjot - thanks.
Is there a way to easily set the width of the new Page template column? I have unset the author, comment and date columns and would like to right-align the Page template column with the right-hand edge of the screen. - 06/17/12 11:40pm
Navjot Singh says:Try using .column-{name} class to set width of your custom column.
.column-page_template { width:20%; }
should work. - 06/17/12 11:53pm
designbuildtest says:Works great. Thanks.
- 06/17/12 10:52pm
-

Last edited:
06/17/12
10:25pmRomel Apuya says:try this
function add_page_text_column($page_columns) {
$page_columns['page_template'] = "Page template";
return $page_columns;
}
add_action('manage_pages_columns', 'add_page_text_column');
function show_page_template_column($post){
global $post;
switch ($post) {
case 'column-page-template':
$page_template = get_post_meta($post->ID, '_wp_page_template', true); // file name
$result = $page_template; // get template nice name
var_dump($result);
echo $result;
break;
default:
break;
}
}
add_action('manage_pages_custom_column','show_page_template_column');
- 06/17/12 10:50pm
designbuildtest says:Doesn't work sorry.
- 06/17/12 10:50pm
-

Last edited:
06/17/12
10:33pmArnav Joy says:try this
function add_page_text_column($page_columns) {
$page_columns['page_template'] = "Page template";
return $page_columns;
}
add_action('manage_pages_columns', 'add_page_text_column');
function show_page_template_column($column_name, $post_id ){
switch ($column_name) {
case 'page_template':
$page_template = get_post_meta($post_id, '_wp_page_template', true); // file name
$result = array_search($page_template, get_page_templates()); // get template nice name
echo $result;
break;
default:
break;
}
}
add_action('manage_pages_custom_column','show_page_template_column',10,2);
Previous versions of this answer: 06/17/12 at 10:33pm
- 06/17/12 10:49pm
designbuildtest says:Works perfectly. Thanks Arnav. Please could you update your code so a default message is displayed if no page template has been defined. Thanks.
- 06/17/12 10:49pm
This question has expired.
Rashad Aliyev, Gabriel Reguly, designbuildtest, Francisco Javier Carazo Gil voted on this question.
Current status of this question: Completed
Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.
If the asker does not get an answer then they have 10 days to request a refund.
