Site logo

Archived topic

child theme: override featured-images + open blog posts full size featured img

1 reply · Started by Webmaster on July 1, 2018

Viewing posts 1–2 of 2

I pasted this snippet into my functions.php and I want to change <a href="%1$s"> so that it opens blog posts full-sized featured image (instead of the blog post itself).

Any tips?

I would like the <a href="%1$s"> to return the_post_thumbnail('full') - https://wordpress.stackexchange.com/a/167309


function generate_post_image() {
    // If there's no featured image, return.
    if ( ! has_post_thumbnail() ) {
        return;
    }

    // If we're not on any single post/page or the 404 template, we must be showing excerpts.
    if ( ! is_singular() && ! is_404() ) {
        echo apply_filters( 'generate_featured_image_output', sprintf( // WPCS: XSS ok.
            '<div class="post-image">
                <a href="%1$s">
                    %2$s
                </a>
            </div>',
            esc_url( get_permalink() ),
            get_the_post_thumbnail(
                get_the_ID(),
                apply_filters( 'generate_page_header_default_size', 'full' ),
                array(
                    'itemprop' => 'image',
                )
            )
        ) );
    }
}

Hi there,

Give this function a shot:

add_filter( 'generate_featured_image_output', 'tu_featured_image_link_to_self' );
function tu_featured_image_link_to_self() {
	return sprintf( // WPCS: XSS ok.
		'<div class="post-image">
			<a href="%1$s">
				%2$s
			</a>
		</div>',
		esc_url( get_the_post_thumbnail_url( get_the_ID(), 'full' ) ),
		get_the_post_thumbnail(
			get_the_ID(),
			apply_filters( 'generate_page_header_default_size', 'full' ),
			array(
				'itemprop' => 'image',
			)
		)
	);
}
This archived topic is closed to new replies.