[Resolved] Featured image not working as expected in link post

Home Forums Support Featured image not working as expected in link post

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1182136
    Sara

    The link post’s title does what I expect – it links to the url of the first link in the post, but the featured image does not (it just opens it up like a standard post). How do I change it?

    #1182420
    Leo
    Staff
    Customer Support

    Hi there,

    By default the title should open the post as the other post.

    I’d assume there is a plugin doing something here.

    Have you tried disable all plugins except GP Premium to eliminate any conflicts?

    Let me know 🙂

    #1182440
    Sara

    No it should not open the post – because it’s configured to be a link post (see this by Tom: “Link takes the first link from the post and makes the post title link to that link.”)

    I’m actually happy that the title links to the first link in the post, but the featured image should do the same, and I think that may be a bug. Let me know what you think.

    #1182857
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this PHP:

    add_filter( 'generate_featured_image_output', function( $output ) {
        if ( ! has_post_format( 'link' ) ) {
            return $output;
        }
    
        return sprintf( // WPCS: XSS ok.
            '<div class="post-image">
                %3$s
                <a href="%1$s">
                    %2$s
                </a>
            </div>',
            function_exists( 'generate_get_link_url' ) ? esc_url( generate_get_link_url() ) : esc_url( get_permalink() ),
            get_the_post_thumbnail(
                get_the_ID(),
                apply_filters( 'generate_page_header_default_size', 'full' ),
                array(
                    'itemprop' => 'image',
                )
            ),
            apply_filters( 'generate_inside_featured_image_output', '' )
        );
    } );

    Let me know 🙂

    #1183129
    Sara

    Perfect 🙂

    Thank you!

    #1183777
    Tom
    Lead Developer
    Lead Developer
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.