[Support request] Use featured image as link for a fancy lightbox :)

Home Forums Support [Support request] Use featured image as link for a fancy lightbox :)

Home Forums Support Use featured image as link for a fancy lightbox :)

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #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!

    #2522427
    Ying
    Staff
    Customer Support

    Hi Erwin,

    Any chance you can link us to an example?

    Let me know πŸ™‚

    #2522448
    Erwin

    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.

    #2522451
    Leo
    Staff
    Customer Support

    Is the actual lightbox feature required or the core Link to Media option will work?

    Let me know πŸ™‚

    #2522455
    Erwin

    I suppose the core link would be enough as the lightbox plugin should take over from there. πŸ™‚

    #2522456
    Leo
    Staff
    Customer Support

    Can you link me to the page in question so I can see the current layout and provide the easiest and best solution?

    #2522462
    Erwin

    Link
    (it’s kinda empty :P)

    #2522600
    Leo
    Staff
    Customer Support
    #2522896
    Erwin

    I pasted the code into my functions.php, but it didn’t change anything. πŸ™

    Any other suggestions? πŸ™‚

    #2522904
    Fernando
    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', '' )
        );
    } );
    #2523572
    Erwin

    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.

    #2523583
    Leo
    Staff
    Customer Support

    What 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', '' )
        );
    } );
    #2523592
    Erwin

    BINGO! πŸ₯³

    #2523863
    Leo
    Staff
    Customer Support

    Awesome.

    Looks like the conditional tags were the culprit πŸ™‚

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.