- This topic has 13 replies, 4 voices, and was last updated 1 month, 3 weeks ago by
Leo.
-
AuthorPosts
-
February 5, 2023 at 9:46 am #2522326
Erwin
Hellos!
I’d like to use the featured images of both the blog index and the single posts to link to the full image so a fancy lightbox gets triggered when clicked on it. If possible also the post title…
I’ve read a bunch of posts, but I can’t get it to work….halp? π
Happy Sunday!
February 5, 2023 at 11:49 am #2522427Ying
StaffCustomer SupportHi Erwin,
Any chance you can link us to an example?
Let me know π
February 5, 2023 at 12:08 pm #2522448Erwin
Well, no. Because I can’t get it to work. π
What I’d like is for featured images to link to the original full-size instead of to the single posts. A lightbox plugin will then do the lightbox stuff.
Same for featured images in single posts: link to the original full-size image.
February 5, 2023 at 12:10 pm #2522451Leo
StaffCustomer SupportIs the actual lightbox feature required or the core Link to Media option will work?
Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/February 5, 2023 at 12:18 pm #2522455Erwin
I suppose the core link would be enough as the lightbox plugin should take over from there. π
February 5, 2023 at 12:19 pm #2522456Leo
StaffCustomer SupportCan you link me to the page in question so I can see the current layout and provide the easiest and best solution?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/February 5, 2023 at 12:28 pm #2522462Erwin
Link
(it’s kinda empty :P)February 5, 2023 at 4:55 pm #2522600Leo
StaffCustomer SupportCan you try the second example here?
https://docs.generatepress.com/article/generate_featured_image_output/#exampleAdding PHP: https://docs.generatepress.com/article/adding-php/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/February 6, 2023 at 1:19 am #2522896Erwin
I pasted the code into my functions.php, but it didn’t change anything. π
Any other suggestions? π
February 6, 2023 at 1:30 am #2522904Fernando Customer Support
Can you try this Snippet?:
add_filter( 'generate_featured_image_output', function( $output ) { if ( ! is_category() || ! is_home() || ! is_single() ) { return $output; } return sprintf( '<div class="post-image"> %3$s <a href="%1$s"> %2$s </a> </div>', esc_url( get_the_post_thumbnail_url() ), get_the_post_thumbnail( get_the_ID(), apply_filters( 'generate_page_header_default_size', 'full' ) ), apply_filters( 'generate_inside_featured_image_output', '' ) ); } );
February 6, 2023 at 11:24 am #2523572Erwin
Just as a test I edited the theme file “featured-images.php” and changed “get_permalink” on line 42 in “get_the_post_thumbnail_url” which then actually works. Not on single posts, by the way.
However, I’d like a cleaner solution instead of hacking into theme files… π
I’ll leave it as it is know, so you can see how I want it to work.
February 6, 2023 at 11:42 am #2523583Leo
StaffCustomer SupportWhat if you just use this?
add_filter( 'generate_featured_image_output', function( $output ) { return sprintf( '<div class="post-image"> %3$s <a href="%1$s"> %2$s </a> </div>', esc_url( get_the_post_thumbnail_url() ), get_the_post_thumbnail( get_the_ID(), apply_filters( 'generate_page_header_default_size', 'full' ) ), apply_filters( 'generate_inside_featured_image_output', '' ) ); } );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/February 6, 2023 at 11:47 am #2523592Erwin
BINGO! π₯³
February 6, 2023 at 6:14 pm #2523863Leo
StaffCustomer SupportAwesome.
Looks like the conditional tags were the culprit π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.