0
X
Add Snippet To Project
New Project
Add To Existing Project
<?php
// Add featured image column to posts and post types lists
function atar4u_add_featured_image_column($columns) {
$columns['featured_image'] = __('Featured Image', 'atar4u');
return $columns;
}
add_filter('manage_posts_columns', 'atar4u_add_featured_image_column');
add_filter('manage_pages_columns', 'atar4u_add_featured_image_column');
add_filter('manage_customposttype_posts_columns', 'atar4u_add_featured_image_column');
// Display featured image in the new column
function atar4u_display_featured_image_column($column, $post_id) {
if ($column === 'featured_image') {
if (has_post_thumbnail($post_id)) {
$image = get_the_post_thumbnail($post_id, 'thumbnail');
echo $image;
} else {
echo __('No Featured Image', 'atar4u');
}
}
}
add_action('manage_posts_custom_column', 'atar4u_display_featured_image_column', 10, 2);
add_action('manage_pages_custom_column', 'atar4u_display_featured_image_column', 10, 2);
add_action('manage_customposttype_posts_custom_column', 'wpturbo_display_featured_image_column', 10, 2);
Note:
Please make sure to replace 'customposttype' with the actual slug of your custom post type in the code snippet if you have any.