Support » Plugin: Default featured image » Question – possible issues with fallback thumbnail?

  • 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. 🙂


Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author janw.oostendorp


    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.

    Plugin Author janw.oostendorp


    How did it go?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Question – possible issues with fallback thumbnail?’ is closed to new replies.