Posts Missing a Featured Image Widget
Adds a dashboard widget listing the latest published posts that have no featured image, with edit links, so social shares and archive pages never show blank spaces.
Opens WPIDE on
Code
// Post type to check.
$wpide_thumb_check_type = 'post';
add_action( 'wp_dashboard_setup', function () use ( $wpide_thumb_check_type ) {
wp_add_dashboard_widget( 'wpide_missing_thumbs', 'Missing featured images', function () use ( $wpide_thumb_check_type ) {
$query = new WP_Query( array(
'post_type' => $wpide_thumb_check_type,
'post_status' => 'publish',
'posts_per_page' => 10,
'meta_query' => array( array( 'key' => '_thumbnail_id', 'compare' => 'NOT EXISTS' ) ),
) );
if ( ! $query->have_posts() ) {
echo '<p><span class="dashicons dashicons-yes-alt" style="color:#00a32a" aria-hidden="true"></span> Every published post has a featured image.</p>';
return;
}
printf( '<p>%d posts without a featured image. Latest:</p><ul>', (int) $query->found_posts );
foreach ( $query->posts as $post ) {
printf( '<li><a href="%s">%s</a> <small>%s</small></li>', esc_url( get_edit_post_link( $post ) ), esc_html( get_the_title( $post ) ), esc_html( get_the_date( '', $post ) ) );
}
echo '</ul>';
printf( '<p><a href="%s">See all</a></p>', esc_url( admin_url( 'edit.php?post_type=' . $wpide_thumb_check_type . '&wpide_thumb=without' ) ) );
} );
} );
Notes
Shows up to ten posts; change the post type in $wpide_thumb_check_type.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.