Archived topic
Addling a custom link to featured image on single post
3 replies · Started by Bob on June 30, 2020
I'm trying to add a custom link to a featured image, on a single post (custom post type).
I've tried this, but it does not seem to be working :
https://generatepress.com/forums/topic/add-custom-link-to-featured-image-on-post-page/#post-693006
I am putting it on my custom single post template (the link only need to be there on particular posts, and code on the template will determine if it does/what the link is)
Hi there,
How does the template determine whether to generate a link/what the link should be?
It would determine it based on whether an image gallery exists. I can take care of that aspect, if I can get general code working to wrap the main featured image in a link when needed.
Hi there,
if you have resized the featured images ( prior to GPP 1.11 ) then try using this snippet instead:
add_filter( 'generate_single_featured_image_html', function($image_html) {
if( $image_html == '' ) {
return $image_html;
} else {
$linked_html = '<a href="#YOUR-URL">' . $image_html . '</a>';
}
return $linked_html;
});