Default featured image
[resolved] Default Image based on First Image in Post (7 posts)

  1. MCM
    Posted 3 years ago #

    I have a number of posts, who already have images inside the posts (but not set as featured images).

    I found a plugin that sets the image as featured if it contains a image but then your plugin overrides this by placing a default image as it does not contain an image.

    Is there a way around this perhaps please?


  2. janw.oostendorp
    Plugin Author

    Posted 3 years ago #

    Wow, that's a tricky one. You could exclude those posts by ID. I got an example in the FAQ.
    But that would require you to keep adding post ID's to the exception.

    I would recommend:

    1. exclude the whole poststype (again check the FAQ).
    2. Where you put echo the Featured image do an manual check if one is set.
    3. If not, get and echo the default featured image, see code below:
    <br />
    $dfi= wp_get_attachment_image( get_option( 'dfi_image_id' ), $size, false, $attr );<br />
    echo $dfi;<br />

    I hope this helps. If you get stuck let me know and I will give more detailed instructions and help where needed.

  3. MCM
    Posted 3 years ago #

    Thanks, so I know what I want now and hope you can help.

    I think an easier solution.

    Basically I have two custom posts - I do not required default image for normal posts.

    I installed your plugin and did not specify a default image BUT I created the necessary functions for those custom posts.

    If I enable default featured image, it then works 100% BUT it then also works for POSTS! :(

    Is there a way to tell your plugin NOT to even process posts, as I have another plugin that fetches the first image in the posts and displays it as a thumbnail.


  4. janw.oostendorp
    Plugin Author

    Posted 3 years ago #

    pasting below in your functions.php should exclude all posts form my plugin.

    function dfi_posttype_post( $dfi_id ) {
      if ( is_singular( 'post' ) || get_post_type() == 'post' ) {
        return 0; // it's an invalid ID
      return $dfi_id; // the original featured image id
    add_filter('dfi_thumbnail_id', 'dfi_posttype_post' );

    Let me know ;)

  5. MCM
    Posted 3 years ago #

    Thanks for the feedback but decided to use post format.

  6. janw.oostendorp
    Plugin Author

    Posted 3 years ago #

    No problem, thanks for getting back at me ;)

  7. MCM
    Posted 3 years ago #

    :) I actually ended up using your plugin. Thanks though I dont deserve your efforts now :)

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


No tags yet.