Support » Plugin: Multiple Post Thumbnails » How to fallback to regular featured image?

  • Resolved Marvel Themes

    (@builtwithfoundation)


    I’m wanting to use this plugin to show a different image on the catalog page for Woocommerce, but if the second featured image is not set, then I want it to fallback to the normal featured image.

    I’m having a problem getting it to work. The below code is showing both the first and second featured images if both are defined, but only shows the first if it’s the only one defined.

    So why am I seeing two featured images if both are defined?

    function woocommerce_template_loop_product_thumbnail(){
      global $post;
      if (class_exists('MultiPostThumbnails') && MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image') !== null) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image');
      elseif ( has_post_thumbnail() ) : echo get_the_post_thumbnail( $post->ID, 'thumbnail');
      elseif ( wc_placeholder_img_src() !== null) : $dimensions = wc_get_image_size( $size ); echo '<img src="' . wc_placeholder_img_src() . '" alt="Placeholder" width="' . esc_attr( $dimensions['width'] ) . '" class="woocommerce-placeholder wp-post-image" height="' . esc_attr( $dimensions['height'] ) . '" />';
      endif;
    }

    https://wordpress.org/plugins/multiple-post-thumbnails/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to fallback to regular featured image?’ is closed to new replies.