I’m been working extensively on WordPress related development recently and have come across very interesting customization that you can incorporate into your WordPress system. I soon realised that i was unknowingly developing an interesting repository of techniques which can be used by others too. So, I decided to start writing about these tips and tricks to make it available to other fellow developers like myself.
Today, in this post I’m going to explain to you how to add a featured image column in admin dashboard. So, where exactly will this image be displayed to the users? Well, in the admin dashboard the users will be able to see the featured image on the all posts page. An extra column will be added to the table displaying the list of all posts on the website blog.
It will look something as below!
Steps to Add a Featured Image Column in Admin Dashboard
Step 1: In order to make the featured image visible in the admin dashboard the first thing to do would be to set the featured image a blog post. The feature image can be added from the post page in the admin dashboard.
Step 2: Now the user will have make changes to the functions.php file in order to make the featured image visible in the default listing of posts in the admin dashboard. The manage_posts_columns filter provided by WordPress will be used to achieve this result. This filter allows you to add columns to the list pages in the admin dashboard.
add_filter('manage_posts_columns', 'posts_columns');
Step 3: Along with this you will have to use the manage_posts_custom_column hook to name the column that is being added to the default post list in dashboard and to specify the size of the featured image thumbnail that will be displayed in the admin dashboard.
add_action('manage_posts_custom_column', 'posts_custom_columns'); function posts_columns($defaults){ $defaults['wdm_post_thumbs'] = __('Featured Image'); //name of the column return $defaults; } function posts_custom_columns($column_name, $id){ if($column_name === 'wdm_post_thumbs'){ echo the_post_thumbnail(array(100,100)); //size of the thumbnail } }
However the one thing to note here would be that if the theme is updated then the code that has just been added will be overridden.