[Support request] child theme: override featured-images + open blog posts full size featured img

Home Forums Support [Support request] child theme: override featured-images + open blog posts full size featured img

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

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #612933
    Webmaster

    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',
                    )
                )
            ) );
        }
    }
    
    #613077
    Tom
    Lead Developer
    Lead Developer

    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',
    			)
    		)
    	);
    }
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.