generate_featured_image_output

The generate_featured_image_output allows us to alter the HTML of the featured image on the posts/blog and archives.

Example

If we don’t want a link surrounding the featured image:

add_filter( 'generate_featured_image_output', function( $output ) {
    return sprintf( // WPCS: XSS ok.
        '<div class="post-image">
                %2$s
         </div>',
         esc_url( get_permalink() ),
         get_the_post_thumbnail(
             get_the_ID(),
             apply_filters( 'generate_page_header_default_size', 'full' ),
             array(
                 'itemprop' => 'image',
             )
         )
    );
} );

We can also use the snippet below to link the featured image to the media file instead of single posts:

add_filter( 'generate_featured_image_output', function( $output ) {
    if ( ! is_category() ) {
        return $output;
    }

    return sprintf(
        '<div class="post-image">
            %3$s
            <a href="%1$s">
                %2$s
            </a>
        </div>',
        esc_url( get_the_post_thumbnail_url() ),
        get_the_post_thumbnail(
            get_the_ID(),
            apply_filters( 'generate_page_header_default_size', 'full' )
        ),
        apply_filters( 'generate_inside_featured_image_output', '' )
    );
} );