WordPress is a great platform for building any kind of websites and it has a sufficient back-end, but sometimes you need to make changes in layout.
In this post, we’re going to go through how to add a new column into post listing dashboard of WordPress admin.
Let’s dive into the steps to add featured image into the post listing page.you need to add below code into your theme’s function.php file.
First of all, you need to write add filter and add_filter used to add new label of column is manage_post_posts_columns
.
1 2 3 4 5 6 7 8 | function post_thumbnail_column( $cols ) { $cols['thumbnail'] = __('Featured Thumbnail'); return $cols; } add_filter( 'manage_post_posts_columns', 'post_thumbnail_column' ); |
Must Read: How to use Ajax in WordPress with example
Next, you can add action which will be useful to display image into listing page.Here I wanted to display featured image so I have used function get_the_post_thumbnail.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | add_action( 'manage_posts_custom_column', 'custom_thumbnail_column' ); function custom_thumbnail_column( $column ){ global $post; $custom = get_post_custom(); switch ($column) { case 'thumbnail' : if (has_post_thumbnail($post->ID)) echo get_the_post_thumbnail($post->ID, 'thumbnail'); break; } } |
Read about: Customize Contact Form 7 in WordPress
Here,get_post_custom
function which returns values with all custom fields of a particular post or page.here case is the key of the array passed to create a label.
So, now you have a new column in post listing.you can see into your WordPress backend.you can add any field by following above steps.
Thank you for reading.Feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.