Archived topic
Featured image not working as expected in link post
5 replies · Started by Sara on March 2, 2020
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?
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 :)
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.
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 :)
Perfect :)
Thank you!
You're welcome :)