The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Default featured image
Question - possible issues with fallback thumbnail? (3 posts)

  1. Demorden
    Posted 2 years ago #

    Pretty much as I asked in the title...

    My site already has a fallback solution for featured images: it takes the first post image if no thumbnail is manually set.

    I'm working on a big job, I should finally be close to finish it and, before installing, I'd like to know if there are known compatibility issues with this kind of function.

    To make it perfectly clear, my goal is to have a featured image chosen as follows.

    If I set one, use that one;
    if I don't set one, but the post has (at least) a picture, use that picture;
    if the post has no pics of any kind, use a default fallback image.

    Will this work like that?
    Thanks in advance for taking the time to answer. :)



  2. janw.oostendorp
    Plugin Author

    Posted 2 years ago #

    Short answer: Yes, but you have to code it yourself.

    Longer answer: It depends on how you are doing this. I don't know your code. Or your how far you are with WordPress coding. But I'll give a general idea how to do it.

    You can use the dfi_thumbnail_id filter.

    function check_for_image_in_post( $dfi_id ) {
        // check the post for an image. I guess you made something to do that.
        global $post;
        if ($post === has_image_in_post_content()) { // dummy if
          // I won't make this magic
          return $first_image_in_post_id;
        return $dfi_id; // the original featured image id
      add_filter('dfi_thumbnail_id', 'check_for_image_in_post' );

    If you create something like this in the themes functions.php
    Remember you need to return the attachment id, not html of an image.

    I guess you are using has_post_thumbnail() to 'switch' but in my scenario all you need to do is give the id though the filter and use the_post_thumbnail() to display the image.

    Hope you can figure it out.
    Let me know.

  3. janw.oostendorp
    Plugin Author

    Posted 2 years ago #

    How did it go?

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Default featured image
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic