Patrick Galbraith

Web developer - Adelaide, Australia

Default Thumbnail Plus 120

WordPress Plugin

Automatically display a default Post Thumbnail image, either the first image attached to a post, or set default images for specific categories, tags, or custom taxonomies. Supports custom fields to ease upgrading.

Download: http://wordpress.org/extend/plugins/default-thumbnail-plus




 
 

Thumbnail Selection Hierarchy

The hierarchy below determines what thumbnail will be chosen, in other words the plugin first checks if the user has manually set a featured image. If not then it checks if it has a custom field containing an attachment id, and so on. Once the plugin gets to the last step if no default thumbnail image is set then no post thumbnail will be displayed.

  1. Featured Image
  2. Custom Field
  3. Image Attachment
  4. Embedded image
  5. Embedded video
  6. Category/Tag/Taxonomy Thumbnail
  7. Default Thumbnail

Add Filter (Category/Tag/Taxonomy Thumbnail)

You can add filters which allow you to select a thumbnail for a specific category, tag, or custom taxonomy. The value field is required and must contain either a comma separated list of slug, id, or title for a existing category, tag, or custom taxonomy. Any post that does not have a post-thumbnail set and has the specified tag, or is a member of the category or taxonomy will show the default thumbnail specified.

Use image attachment if available

Automatically use the post’s first available image attachment for the thumbnail. This is useful for older posts that haven’t got a featured image set.

Custom Field

Enter a custom field key here, it’s value if set will become the default post thumbnail for that post. The custom field value can either be an Attachment ID, or a link to an image.

Note: If the custom field value contains a link to an image it will output a simple image tag and attempt to populate the width and height attributes. However the aspect ratio may not match other thumbnails. The plugin does not check if the image exists or is of valid type or size.

Use embedded image if available

Automatically use the post’s first available embedded image for the thumbnail. This is useful if you embed external images.

Note: This option does not work with has_post_thumbnail() or get_post_thumbnail_id(). If the “cache external images” option is set then the plugin will automatically resize, crop the image and store a local copy.

Use embedded video if available

Automatically use the post’s first available embedded video for the thumbnail (YouTube only).

Note: This option does not work with has_post_thumbnail() or get_post_thumbnail_id(). If the “cache external images” option is set then the plugin will automatically resize, crop the image and store a local copy.

Excluded posts

List of posts to be ignored by this plugin. Comma separated e.g. 10, 2, 7, 14.

Note: These posts may still display a thumbnail if one has been set manually (using the “Set featured image” button on the post page).

Functions

The following functions work to directly return post thumbnail even if the plugin hooks have been disabled. This allows you to disable the filters and call the plugin manually. This should only be used if you are creating a custom theme and can ensure that DefaultThumbnailPlus is installed.

dpt_post_thumbnail_id($post_id, $size = null, $attr = ”)
Returns the post thumbnail ID. Doesn’t work with embedded images.

dpt_post_thumbnail_html($post_id, $size = null, $attr = ”)
Directly calls the default post thumbnail function. Works the same as calling get_the_post_thumbnail().

dpt_post_thumbnail_src($post_id, $size = null)
Returns href to post thumbnail image.


Why can’t I see any thumbnails with my custom theme?

A number of themes use has_post_thumbnail() to check if a post thumbnail exists before calling the_post_thumbnail() to display the thumbnail. The problem with this is that thumbnails that are linked to directly (either external images or video thumbnails) won’t return correctly for this check and therefore may not show.
 
To fix this issue you will need to look for the following code in your theme:

if(has_post_thumbnail()) {
    the_post_thumbnail(...);
}

 
And simply remove the call to has_post_thumbnail() so you are left with this:

the_post_thumbnail(...);

TwentyEleven

The header only works with image attachments, i.e. embedded images/video thumbnails won’t show.

The header attachment width also has to be greater than the custom-header width option (default 1000px). This is generally a good thing though since it prevents low resolution images from displaying in the header.

WooThemes

WooThemes call a function called woo_image() rather than using the default WordPress functionality. This causes the default post thumbnail to never show.

So to fix this you need to override the woo_image() function with a custom implementation that reverts to using WordPress’s in-built functions. To do this paste the following code into the TOP of the themes functions.php file found in /wp-content/themes/your_themes_name after the opening <?php tag.


//Override the default woothemes image function and revert to using the default wordpress function.
if ( ! is_admin() && ! function_exists('woo_image')){
    function woo_image($args) {
        global $post;

        $size = null;
        $attr = array();
        $before = '';
        $after = '';
        $class = '';

        if ( !is_array($args) )
            parse_str( $args, $args );

        extract($args);

        if(empty($id))
            $id = $post->ID;

        if(isset($width) && isset($height))
            $size = array($width, $height);

        $attr['class'] = 'woo-image '.$class;

        if(isset($alt))
            $attr['alt'] = $alt;

        $output = $before . get_the_post_thumbnail($id, $size, $attr) . $after;

        if($return == TRUE)
            return $output;
        else
            echo $output;
    }
}

 
The downside is that it won’t recreate all of woo_image()’s features. However it shouldn’t cause issues with most themes.

COMMENTS

Leave a reply

  1. I was very interested in this plugin as it was trying to do exactly what I was trying to do, namely to get post thumbnails on the basis of image attachment or a default. The plugin does not recognize images that are linked to an external site (e.g. flickr.com). So even if there is an image present, the plugin chooses the default image. Could you help in this regard please? I am an absolute newbie in php.

  2. jonathan said

    Any hints on how to get this to work with arras theme? Looks snappy really want to use it, but for some reason its having zero effect on my blog.

    • Because that theme has its own custom get_thumbnail function you will need to modify the theme to make it work.
       
      In the file arras/library/thumbnail.php change the arras_get_thumbnail() function on line 73 to this:
       

      function arras_get_thumbnail($size = 'thumbnail', $id = NULL) {
      	global $post, $arras_image_sizes;
              
              if ($post) $id = $post->ID;
      
              return get_the_post_thumbnail( $id, $size, array(
      				'alt' 	=> get_the_excerpt(), 
      				'title' => get_the_title()
      			) );
      
      }
  3. Sweet! Looks like that solution is working like a charm. I’ll let you know if anything ends up being broken – but so far, nope!

  4. Erik said

    Great plugin and I have it working on one site, but on another site I have running a different theme (Instinct – http://newwpthemes.com/instinct-free-wordpress-theme/) it doesn’t work. I imagine there is a coding change like the one above to fix it but I’m not handy with coding to be able to fix it. Any ideas?

    • The problem with that theme is that it checks if the post has a thumbnail before displaying it using the has_post_thumbnail() function. Since the post technically doesn’t have a thumbnail set nothing will show. You can fix it by modifing the theme files (post.php, post-single.php, etc…) and change this:
       

                 if(has_post_thumbnail())  {
                      the_post_thumbnail(
                          array($theme->get_option('featured_image_width_single'), $theme->get_option('featured_image_height_single')),
                          array("class" => $theme->get_option('featured_image_position_single') . " featured_image")
                      );
                  }

       
      Basically just remove the if statement that checks has_post_thumbnail(), so it becomes this:
       

                      the_post_thumbnail(
                          array($theme->get_option('featured_image_width_single'), $theme->get_option('featured_image_height_single')),
                          array("class" => $theme->get_option('featured_image_position_single') . " featured_image")
                      );
  5. Aaron Harquenin said

    Hi

    Ive created a theme from scratch and its fairly clean and basic. When i install your plugin it works on the admin panel but i cannot see the result being rendered in the site face.

    can you please help me?

    Thank you

    • Hi Aaron,
       
      Make sure you aren’t calling has_post_thumbnail() before the displaying the thumbnail since has_post_thumbnail() will return false.
       
      if(has_post_thumbnail()) {
      the_post_thumbnail(...

       
      Otherwise there isn’t much I can do unless you send me your theme’s files.

  6. Kalynbm said

    Patrick hey, this is the plugin that I’ve been looking high and low for, but I couldn’t get it to work with the theme that I’m currently using, the theme’s name is Mingle. I hope you can point me to the problem, and thanks in advance. :)

  7. My problem is the selected default image does not show and when clicked on to show the image gets a 500 error, the image folder is in the plugin folder and has a default in it but that doesn’t show either… what am i doing wrong

    • Hi Jonathan,
       
      It sounds like a theme related issue can you tell me what theme you are using or if it a paid theme can you post the code from the theme that calls the_post_thumbnail(…).

  8. Kalynbm said

    Hey Patrick,

    I swore I hit submitted, but I guess the comment didn’t show up. So here I go again…lol. So I’ve been searching high and low for a plugin like this one, and I’m glad that I found it, but the problem is that I can’t get it to work on my theme, the theme’s name is Mingle. I have tried using ID, slugs and title for the value but it still doesn’t show up. :( Can you point me to the problem? And thanks in advanced. :)

    • Hi Kalybm,
       
      Your comments weren’t shown because it was flagged as spam by Akismet.
       
      I can’t give you specific advice because your theme is a paid one (and I can’t get access to the source).
      Make sure the theme isn’t calling has_post_thumbnail() before the displaying the thumbnail since has_post_thumbnail() will return false.
       
      if(has_post_thumbnail()) {
      the_post_thumbnail(...

       
      Unfortunately I can’t override the has_post_thumbnail() check since WordPress doesn’t provide that option to plugin developers.

  9. Hey, great plugin! When a post has an attachment that is not an image (e.g., a PDF file), no thumbnail is shown.

  10. Kermit Woodall said

    I’m trying out your plugin on our site but it’s not working quite like I expect. It seems to pull images from elsewhere on the page that the post appears on.

    http://test.advocatemag.com/category/blog-post/

    I’m calling the post thumbnails in the Facebook Like button (search the source for fblike) and if you look down the the post for “Crime alert: Police seek help identifying aggravated roberry suspects ” it’s pulling the image of the author shown on the sidebar. Similar issues elsewhere.

    On a post that has no thumbnail, because it’s a video, (“Advocate video: Tiramisu Restaurant “) it actually pulls a thumbnail from the code that generates the grids of video thumbnails below.

    Any ideas?

    Thanks!

    Kermit Woodall

  11. Kermit Woodall said

    Correction… the video post DOES have a featured image thumbnail and there’s something wrong in my code. Hang on while I diagnose this before you waste your time. I think I’m calling the wrong function for showing post thumbnail.

    Kermit Woodall

  12. Kermit Woodall said

    Ok…I did have some bad code in there but have fixed that. Now I’m just not getting any result from using the plugin. No fallback to a default thumbnail and no finding the first image.

    http://test.advocatemag.com/category/blog-post/

    This code, below, is what I use to get the thumbnail link.

    Kermit Woodall

  13. Kermit Woodall said

    `
    <span class='st_fblike_hcount' st_url='’ st_title=’
    ‘ st_image=’
    ‘ st_summary=’
    ‘ displayText=’share’>

    `

  14. Kermit Woodall said

    [code]

    <span class='st_fblike_hcount' st_url='’ st_title=’
    ‘ st_image=’
    ‘ st_summary=’
    ‘ displayText=’share’>

    [/code]

  15. Kermit Woodall said

    Sorry…I’m trying to get the code to show up here and none of the tags seems to work here.

    $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), ‘large’);
    echo $large_image_url[0];

    I’ve tried just the PHP code w/out any tags to see if this will work.

    Kermit Woodall
    http://kermitwoodall.com

  16. Hi. I had requested earlier if the plugin will pull in thumbnails even if the image linked in the post is from an external site like flickr/picasa. Currently even if there is an image link, the default image is used as thumbnail. Is there any code I can change to get this working, please.

  17. Liliz said

    Hi, i am trying to make the plugin work with the Evolution theme which has a piece of code like this in the home template:

    Following your suggestions above i removed the “if” statement. This gives a partial result: empty boxes are showing next to the posts, but i cannot see the images that i assigned with the plugin. Do you have any hint about this?

  18. Hi there… I was using your plugin to see if it would work for one of my clients and I ran into a problem with the Builder theme engine from iThemes. It’s a known problem on their end. Quote:

    Problem: Any time Builder’s editors show a Thickbox dialog (delete confirmation, module editors, etc), the dialog will be broken and appear as an empty white box that flows into the top of the browser window.
    Cause: The plugin enqueues WordPress’ built-in media-upload script on all admin pages (not just its own). Since the media-upload script modifies all uses of Thickbox (also built into WordPress), this causes the Thickboxes in Builder to be broken.

    Is this a known issue that can be taken care of in an update?

    Thanks!

    -Anthony Navarro
    http://thewpdojo.com

    • Hi Anthony,
      It sounds like the plugin you are using is incorrectly enqueueing scripts outside its own page which is causing issues.
      I don’t think there isn’t much I can do to fix that.

  19. Hey Hey.

    I think I’ve struck gold with your plugin. I think it is what I’ve always been trying to do but never could find an eloquent way to implement it.

    I’m having troubles though integrating it with a widget I have.

    Essentially what the widget does is display recent posts and you have the option to display them with or without thumbnails. If you choose ‘with’ it pulls the featured image if there is one, otherwise it simply shows a blank spot where the image should be.

    The site I am building will be used by people who do either do not want to be bothered to upload an image for each post or won’t remember how and thus I’d love to have default thumbnail images to be able to use.

    The code for the widget can be found here: http://pastebin.com/dTXMnzxa

    But the piece of code that I think I’m having trouble with can be found here: http://pastebin.com/rUaidSAd

    I’ve tried removing the “&& has_post_thumbnail” portion, so it isn’t validating against whether or not the post has a thumbnail, which is obviously doesn’t, but still can’t get it to work.

    I didn’t know if “get_the_post_thumbnail” was the right function to be using, or if it is because no category information is being passed to the widget function.

    I know this is a very specific question but I’ll most definitely donate to the plugin (and you) if I can get it working.

    Any help would be appreciated, but if it isn’t possible I understand.

  20. oh, not that it matters, but so you can see how it is visualized, this is the theme that I’ve used as a base for what I am doing: http://studiomw.co.uk/demo/ecclesia/

  21. Turns out I can’t seem to pull the images anywhere in my theme, even just in an individual post.

    I must be an idiot.

  22. Patrick.

    Thanks for the reply.

    Once I got your message this morning I decided to play around more.

    I didn’t know that plugin existed but have bookmarked it for future use when I have a site that doesn’t have a similar function already.

    I realized that what was happening is that the Default Thumbnail plugin wasn’t liking the category slug, so I tried using the cat id and that didn’t work either, what did end up working was the actual cat name, which I never thought to try as typically it doesn’t work and the others do.

    Anywho, I got it working by calling get_the_post_thumbnail so all is good.

    I’ll donate a bit when my next payment comes in from my client for this work.

    Cheers,

    Kevin

  23. Thanks for the great plugin! Finally got it working.

    Is it possible to extract thumbnails from externally linked images? Some of my posts contains all photos from Flickr and non uploaded directly into the Media Library. :(

  24. Hi Patrick, thanks for designing this plugin, it’s exactly what I’ve been looking for! I’m having some difficulty making it work with Suffusion theme, though – any help you can give me would be hugely appreciated. Thanks in advance.

  25. Thank You!!!
    I’ve been looking for a plugin that did this since FOREVER!

    Didn’t work straight away for me on my custom theme, but your advice above was spot on about “if(has_post_thumbnail()) {”

    Again, thanks!

  26. Hi great plugin, just one question as it doesn’t seem to work down the category hierarchy ie I would like to set a default thumbnail for a parent category and have all the children inherit that thumbnail too. Is this possible, or could each filter at least accept a comma separated list of slug/ids etc to save creating a filter for each parent and one for each of the children too? Cheers.

  27. Also, next question I have just realised I am using the post_thumbnail in certain situations to create a background image. Any idea how I can get the url of the default thumbnail your plugin uses rather than the call to get_post_thumbnail, am currently using wp_get_attachment_image_src for the ones that do have a thumbnail set. Cheers (x2!)

  28. Comment

    Patrick, this is an awesome plugin. Thank you very much. It saved me the work of coding something similar (but much, much, much less polished) to get category images.

    I do have a question/suggestion for future releases. I’ve got one category that gets lots of posts on my site (http://www.gnomestew.com). For that category, we’ve got many images to use. If the plugin randomly selected (or selected from the images in order) from multiple images with the same category listing, that would be an amazing feature. I’m not sure how much utility it would have to most people, but it is a thought.

    Once again, thank you for the already incredible plugin!

    – JOhn

  29. Mark said

    Patrick, multi-image patch by Phuc PN is working properly! Can you add this feature in your plugin?

  30. pleasespamjosh said

    Thank you for the plugin. I’m using TheCotton Theme by Pexeto. I believe that something in the theme is preventing it from allowing the plugin to work properly. It recognizes a featured image properly, but without that…nada. I’m hoping to pull the thumb

  31. Great looking plugin, Patrick, but it looks like I have the same issue as others. I’ve added an image for ‘no image’ and one for a category, neither are showing. Can you advise what part of the theme I need to change to make it work. Happy to donate too :)

  32. Paul Simbeck-Hampson said

    Update: No assistance required now. Regards…

  33. Update: No assistance required now, regards…

  34. Very exciting plugin. It will solve a slew of issues if I can get it going!

    Can i get some help with the immersion theme? http://pixelthemes.net/immersion/

    I’ve located all instances of has_post_thumbnail (content.php, content-image.php, includes/content-.php, & includes/content-image.php) and removed the if statement and can’t seem to affect a change.

    • Hi R Op,
      Sorry there isn’t really anything I can do since that is a paid theme and I can’t get access to the source code.

  35. Andrey said

    Hi Patrick, I doesn’t work with 2011 theme.

    • Hi Andrey,
      Can you let me know what the issue is?
      I only found one small bug but that is fairly minor. The images show up fine for me on my test server.
      Patrick

  36. Peter said

    Patrick, your plugin doesn’t work with the Twenty Eleven theme.

    • Hi Peter,
      Can you let me know what the issue is?
      I only found one small bug but that is fairly minor. The images show up fine for me on my test server.
      Patrick

  37. Kermit Woodall said

    I would like to use your plugin but find it’s not working on the responsive themes I’m using. They don’t post_thumbnail but instead use get_post_thumbnail_id … would it be possible for your plugin to support that as well?

  38. Kermit Woodall said

    Patrick,

    It seems to work well, except, that if there is an actual Featured Image already set it still overrides that.

    All the posts referenced in the slideshow at the top of this page have a featured image set.

    http://newsite.advocatemag.com/

    Kermit Woodall

  39. Kermit Woodall said

    Oops! Found one more bug. I cannot ‘Select Image’ when I try to change the default thumbnail in the settings for DTP. I can click that button all I want but nothing results.

    Kermit Woodall

  40. Andrey said

    Hi Patrick,

    My 2011 theme doesn’t show thumbnails at all. Also I tried to upload standard thumbnail for the case when a post doesn’t have pics, it doesn’t receive this thumbnail.

  41. Hey Patrick,

    Your plugin looks perfect for my site where I have a bunch of old posts and new posts in a category that won’t have featured images.

    But I can’t get it to work with my theme, even after deleting the has_post_thumbnail() check. Here’s the code for a search results page. Any suggestions?

    http://pastebin.com/RqteuXHv

  42. Thanks Patrick. Just installed and it works! I’ll let you know if I discover anything wonky.

  43. Hi.
    Thank you very much for making this plugin!! It’s really cool!
    Usually I only copy the images in Word doc. and then paste them on WordPress…
    Do you know if there is anyway that I can make thumbnails for the first image I “paste” on every posts?
    Thanks again!

    • Hi GourmeSY,
      Can you update to 1.0.2.2. The new version has a option called “Use embedded images if available” which you should enable and should fix your issue.

  44. Thanks! I tried that but it doesn’t work….
    I’m not sure whether the images i used are embedded or not.
    I have a second blog on other website. After I finished a post, I copy the entire post and paste it on WordPress.
    When people click on the image, it brings them straight to my second blog.

    • Could you send me a link to the blog.
      Also let me know what theme you are using since not every theme supports that option.

  45. My website is http://gourmesy.erufa.com/
    and I am using “Glossy Stylo”.
    Thank you!!

    • Hi GourmeSY,
      What plugin are you using to display “Related posts”?
       
      Also the food on your blog looks really tasty

  46. Andrey said

    Hi Patrick,

    I can’t still save default thumbnail with your new version(2011 theme).

  47. I’m using “Related Posts Thumbnails”.
    Thank you!! Heheee:DD

    • Hi GourmeSY,
      Unfortunately that plugin uses a method called get_post_thumbnail_id() which doesn’t work with embedded thumbnails.
       
      See my comment below for fix

    • Oops made a mistake see updated code below.

  48. I tried $image = dpt_post_thumbnail_src( $post->ID, $poststhname );
    doesn’t work…><~

    • Hi GourmeSY,
      Sorry here is the updated version:
       
      Replace this on line 254:
       

      if ( current_theme_supports( 'post-thumbnails' ) ) { // using built in WordPress feature
          $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
          $debug .= 'Post-thumbnails enabled in theme;';
          if ( !( empty( $post_thumbnail_id ) || $post_thumbnail_id === false ) ) { // post has thumbnail
              $debug .= 'Post has thumbnail '.$post_thumbnail_id.';';
              $debug .= 'Postthname: '.$poststhname.';';
              $image = wp_get_attachment_image_src( $post_thumbnail_id, $poststhname );
              $url = $image[0];
              $from_post_body = false;
          }
          else
              $debug .= 'Post has no thumbnail;';
      }

       
      With this:
       

      if ( current_theme_supports( 'post-thumbnails' ) ) { // using built in WordPress feature
          $debug .= 'Post-thumbnails enabled in theme;';
          $image = dpt_post_thumbnail_src( $post->ID, array($width, $height) );
          $url = $image;
          $from_post_body = false;
      }

       

  49. Thanks a lot, Patrick!!!!!!!
    It works like magic!!! Thank you very much for your help and patience.
    I really really appreciate it!! >3<

    • No problem.
      Make sure you upgrade the plugin to 1.0.2.3 when it becomes available since I found a small bug that may cause some images to show as white the first time they are loaded (however it works once page is reloaded so it’s not a big issue).

  50. Got that!
    Thanks! It’s really a great plugin!

Leave a Reply to R Op Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

PINGBACKS