Making WordPress image management easier for your editors

I am man­ag­ing a Word­Press site with a lot of edi­tors and con­trib­u­tors. They are not all equally up to pace with Word­Press and how it works, or at least they have dif­fer­ent ways of doing things. One thing that has proved to be a chal­lenge is the way Word­Press han­dles thumb­nails. My edi­tors and con­trib­u­tors often miss the ‘set as post thumb­nail’ link,  lead­ing to the lack of thumb­nails on the front page.

In this post I will try to explain, how I have made a fall­back, mak­ing it sort of OK for my users to for­get about the thumbnail.

A lit­tle history

Once upon a time, before ver­sion 2.9, Word­Press did not sup­port post thumb­nails. But there were work arounds. One of the best, I ever found, was from a web­site called wp-fun.co.uk. Sadly, the site is gone today, but I man­aged to dig up the old post ‘Easy Peasy Images Sug­ges­tion Roundup’ by Andrew Rick­mann on Archive.org.

Andrew wrote a nice lit­tle PHP class to include in your func­tions file, which gets the first thumb­nail image attach­ment from Word­Press posts. Luck­ily, I also man­aged to dig that one up on Archive.org. Go grab it here: post_imagephp.txt (remem­ber to rename .txt to .php, before includ­ing it in your functions.php file).

So why are You telling me about antiques like this?”, You ask. Because we can use it with advan­tage in our fall­back for peo­ple, who for­get to click the lit­tle ‘set as post thumb­nail’ link.

That way, a thumb­nail will still be dis­played with the post, as long as the edi­tor has just attached an image. If there are no images attached at all, we can always dis­play a default thumbnail.

The fall­back

Let’s take a peek at the code. Put the fol­low­ing where you would nor­mally use the_post_thumbnail().

<?php
// First of all, check if there are any image attachments at all.
$imgargs = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $post->ID,
'post_mime_type' => 'image',
'post_status' => null,
'numberposts' => -1,
);
$attachments = get_posts($imgargs);
// Next, check if there is a manually chosen thumbnail.
if ( has_post_thumbnail() ) {
the_post_thumbnail('thumbnail');
}
// If there are no manually chosen thumbnails, check if there is an image attachment.
elseif ( $attachments ) {
// If there is an image attachment, call Andrew Rickmanns the_image function to get the thumbnail
the_image('thumbnail','attachment-thumbnail wp-post-image',false,false,true);
} else {
// If there are no attachments at all, display a default thumbnail.
?><img class="attachment-thumbnail wp-post-image" alt="" src="<?php bloginfo('stylesheet_directory'); ?>/the/path/to/your/image.jpg" />
<?php }?>

Require­ments:

Remem­ber to include this file, renamed to .php, in your functions.php: post_imagephp.txt