How to add featured image column on all posts WordPress
One of the most useful features in WordPress is the ability to add featured images to posts, which helps in making your content visually appealing. However, the default WordPress admin panel does not display featured images in the posts list. This blog post will guide you through various methods to add a featured image column to all posts in WordPress.
Why Add a Featured Image Column?
Before diving into the methods, it’s important to understand why you might want to add a featured image column to your WordPress posts list:
- Visual Reference: Quickly see which posts have featured images and what they look like.
- Improved Workflow: Makes it easier to manage and update featured images without opening each post.
- Content Quality: Helps in ensuring that all posts have featured images, maintaining a consistent look across your site.
Methods to Add a Featured Image Column
Method 1: Using a Plugin
The easiest way to add a featured image column to your posts list is by using a plugin. Here are two popular plugins that can help you achieve this:
Method 1: Using a Plugin
The easiest way to add a featured image column to your posts list is by using a plugin. Here are two popular plugins that can help you achieve this:
Method 2: Custom Code
If you prefer not to use a plugin, you can achieve the same result by adding custom code to your active theme’s functions.php
file or add it from any snippets plugins.
// Add Featured Image Column to Posts List
function wpexpertguide_add_featured_image_column($columns) {
$columns = array_slice( $columns, 0, 1, true )
+ array( 'featured_image' => 'Featured Image' ) // our new column
+ array_slice( $columns, 1, NULL, true );
return $columns;
}
add_filter('manage_post_posts_columns', 'wpexpertguide_add_featured_image_column');
// Display Featured Image in Column
function wpexpertguide_display_featured_image_column($column, $post_id) {
if ($column == 'featured_image') {
$post_thumbnail_id = get_post_thumbnail_id($post_id);
if ($post_thumbnail_id) {
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'thumbnail');
echo '<img data-id="'.$post_thumbnail_id.'" src="' . $post_thumbnail_img[0] . '" width="50" height="50" />';
}
else {
echo '<img data-id="-1" src="placeholder-image.png" width="50" height="50" />';
}
}
}
add_action('manage_posts_custom_column', 'wpexpertguide_display_featured_image_column', 10, 2);
Here we want to add our custom column at the very beginning – just after the checkbox and before the title, so we have used array_slice()
PHP function here. But if the column order really doesn’t matter for you, you can use just $cols[ 'featured_image' ] = 'Featured Image'
.
add_filter('manage_{CPT NAME}_posts_columns', 'wpexpertguide_add_featured_image_column');
This is the filter hook to which you are attaching your function. It targets the columns displayed in the admin list table for a custom post type.{CPT NAME}
should be replaced with the actual name of your custom post type. For example, if your custom post type is called book
, you would use 'manage_book_posts_columns'
.
Also check this related guide regarding adding featured image option in quick edit wordpress
Conclusion
Adding a featured image column to your WordPress posts list can significantly improve your content management workflow. Whether you choose to use a plugin or add custom code, the process is straightforward and can be tailored to your preferences. By following the methods outlined in this post, you can ensure that your posts are visually appealing and consistently display featured images, enhancing the overall look and feel of your website.