• I’m using post feeds in Meta Slider and it requires that the post (custom post in my case) has a featured image. So when a transparent png is set for each post, the slider works fine.

    How can I automatically set the featured image for a custom post type to transparent.png

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Tellyworth

    (@tellyworth)

    There’s a plugin that sounds like it does what you need:

    https://ww.wp.xz.cn/plugins/wp-auto-featured-image/

    Thread Starter powerj

    (@powerj)

    Thanks Alex. I have tried to use this plugin but it seems to have some bugs in the latest version. Is there an alternative?

    Thread Starter powerj

    (@powerj)

    I’ve come up with this, but its obviously not quite right – not sure also at what point it applies the image

    add_filter('post_thumbnail_html', 'wt_modify_post_thumbnail_html', 99, 5);
    function wt_modify_post_thumbnail_html() {
    if ( has_post_thumbnail() &&  get_post_type() == 'testimonials' )  {
       the_post_thumbnail();
    } else {
        echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/transparent.png" />';
    }
    }
    Clarion Technologies

    (@clarionwpdeveloper)

    Hello powerj,

    The filter applies the image when there was no featured image is applied post in post type=”testimonials”.

    Thanks

    Thread Starter powerj

    (@powerj)

    It doesn’t work though …

    Michael

    (@alchymyth)

    filter should return the results, not echo it;
    https://codex.ww.wp.xz.cn/Plugin_API

    try to modifiy your code accordingly:

    add_filter('post_thumbnail_html', 'wt_modify_post_thumbnail_html');
    function wt_modify_post_thumbnail_html( $html ) {
    if ( !$html &&  get_post_type() == 'testimonials' )  $html = '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/transparent.png" />';
      return $html;
    }

    related http://justintadlock.com/archives/2012/07/05/how-to-define-a-default-post-thumbnail

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Set a default featured image’ is closed to new replies.