- This topic has 7 replies, 3 voices, and was last updated 3 years, 5 months ago by David.
-
AuthorPosts
-
June 19, 2020 at 2:18 am #1333738Bas
Perhaps a stupid question about something I believe is a standard feature on other themes, but I couldn’t find it in GP:
How can I make the featured images on the single posts and pages ‘clickable’ and linking to the original image?
I’m using the Photoswipe lightbox.
June 19, 2020 at 3:45 am #1333834DavidStaffCustomer SupportHi there,
try this PHP Snippet:
add_filter( 'generate_single_featured_image_html', 'custom_add_post_thumbnail_link',25,1 ); function custom_add_post_thumbnail_link($image_html) { if( $image_html == '' ) { $image_html = $image_html; } else { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large'); $linked_html = '<a href="' . $large_image_url[0] . '">' . $image_html . '</a>'; } return $linked_html; }
It will add a link to the Large image.
June 19, 2020 at 4:12 am #1333869BasThanks! How can it link to the full-sized image? We’re very consistent about images sizes, they’re all maximum 1920 px wide.
June 19, 2020 at 4:29 am #1333887DavidStaffCustomer SupportIn this part of the code:
wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
change
large
tofull
so it becomes:wp_get_attachment_image_src( get_post_thumbnail_id(), 'full');
June 19, 2020 at 5:32 am #1333945BasGreat!
For the people using the Photoswipe lightbox, this lightbox doesn’t work when there’s only one image in the post/image. In that case use the following code:
add_filter( 'generate_single_featured_image_html', 'custom_add_post_thumbnail_link',25,1 ); function custom_add_post_thumbnail_link($image_html) { if( $image_html == '' ) { $image_html = $image_html; } else { $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full'); $linked_html = '<a href="' . $large_image_url[0] . '" data-lbwps-gid=" $large_image_url[0] " >' . $image_html . '</a>'; } return $linked_html; }
June 19, 2020 at 6:51 am #1334017DavidStaffCustomer SupportYou’re welcome and thanks for sharing your final method.
October 24, 2020 at 6:33 pm #1502917ideawrightsDavid this was helpful. I found the hook implementation for apply_filters( ‘generate_single_featured_image_html’, $image_html ); via grep, but it doesn’t seem to be in your hook documentation.
All I found related to featured images was
https://docs.generatepress.com/article/generate_featured_image_output/Also a helpful hook to know about, but not what I needed. It would be helpful to add ‘generate_single_featured_image_html’ to the list here: https://docs.generatepress.com/collection/filters/
Thanks
October 25, 2020 at 7:18 am #1503301DavidStaffCustomer SupportHi Tom,
glad you found it of use. We’re continually reviewing and updating the docs, and yes there are many filters that are not listed ( maybe because there are so many ! ) _ ill get Leo to to take at adding that one.
-
AuthorPosts
- You must be logged in to reply to this topic.