I have added this code to my theme to add a new colmum for showing the featured image in the dashboard post page colmum. It’s working in wordpress default post page, but not in custom post type (my custom post name is photo_gallery).
add_filter('manage_posts_columns', 'posts_columns', 5);
add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 3);
function posts_columns($defaults){
$defaults['riv_post_thumbs'] = __('Thumbnail');
return $defaults;
}
function posts_custom_columns($column_name, $id){
if($column_name === 'riv_post_thumbs'){
echo the_post_thumbnail( array('292, 292') );
}
}
How can I show this custom column as first in my custom post type overview?
I’m not sure what exactly does not work for your custom post type. There are two possible cases:
photo_gallery
is hierarchical. That would mean, neither (column head and values) are shown.Anyway, if you want to add the thumbnail only to your custom post type this code should do it:
By the way, you should use prefixes on your custom functions to avoid collisions. (In this example I used the prefix
wpse_135433_
.The function
wpse_135433_posts_columns()
attaches the column at the first position to the list of columns$defaults
.If you want to use this functionality on more than your custom post type you should use
for non hierarchical post types and
for hierarchical post types. The second parameter passed to the
manage_posts_columns
filter is the current post type.