[Support request] If there is no Featured Image

Home Forums Support If there is no Featured Image

  • This topic has 1 reply, 2 voices, and was last updated 5 months ago by Tom.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1466683
    onalti

    I am using this filter for custom post type. If there is no featured photo, I want to show something else instead. How can I do this?

    add_filter( 'generate_featured_image_output','lh_custom_size' );
    function lh_custom_size($output) {
      if ( is_archive( 'results_category' ) ) {
        return sprintf( // WPCS: XSS ok.
         '<div class="post-image">
                <a href="%1$s">
                    %2$s
                <span class="results_media_stamp shellbell"></span></a>
            </div>',
             esc_url( get_permalink() ),
             get_the_post_thumbnail(
                 get_the_ID(),
                 apply_filters( 'generate_page_header_default_size', '' ),
                 array('itemprop' => 'image', ))
        );
    }
     return $output;
    } 
    #1467706
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this:

    add_filter( 'generate_featured_image_output', function( $output ) {
        if ( is_archive( 'results_category' ) ) {
            if ( has_post_thumbnail() ) {
                return sprintf( // WPCS: XSS ok.
                    '<div class="post-image">
                        <a href="%1$s">
                            %2$s
                            <span class="results_media_stamp shellbell"></span>
                        </a>
                    </div>',
                    esc_url( get_permalink() ),
                    get_the_post_thumbnail(
                        get_the_ID(),
                        apply_filters( 'generate_page_header_default_size', '' ),
                        array('itemprop' => 'image' )
                    )
                );
            } else {
                return 'something else';
            }
        }
    
        return $output;
    } );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.