[Resolved] Remove linked Featured image, not image

Home Forums Support [Resolved] Remove linked Featured image, not image

Home Forums Support Remove linked Featured image, not image

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #238575
    Frode

    Hi

    I added a featured image in a post and it display`s perfect.
    The problem is when I visit the blog and click the image I get a pop up of my hole blog above the site.
    Than I have to close it by clicking the cross in the right corner.
    I do not want that (its not beautiful) and would like to remove the link on the image.

    How can I fix?

    Best Regards

    Frode

    #238750
    Tom
    Lead Developer
    Lead Developer

    It sounds like you have a plugin added that is making all links around images open a lightbox of their destination.

    Good idea if the image is linking to itself or a larger image, not a good idea if it’s linking to another page as the post image does.

    I would suggest letting the dev of that plugin know, as this is a bug in their plugin.

    Of course, you can remove the link using this function: https://gist.github.com/generatepress/65aff21092a25e5a6f97

    Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/

    #238894
    Frode

    Hi

    Thanks for helping.

    You’re right, it was a nextgen plug in that say true to apply image effect on all images. I set it to apply only too nextgen images.

    And now it works.

    Thanks

    Best regards

    Frode

    #238899
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

    #921535
    Sami

    Is it possible to get an updated code to this?

    It still works to remove the link but it adds some strange classes and the style of the images looks different. I guess it’s because the code is 3 years old and some parts of the theme changed. I tried for a few hours but can’t get a clean result, would be great if you could post an updated version.

    #921795
    Leo
    Staff
    Customer Support

    To remove the featured image link on posts page?

    This should work:
    https://docs.generatepress.com/article/generate_featured_image_output/#example

    #922342
    Sami

    It should remove the image links from posts on a CPT archive page and it works perfect, thank you!

    Is it possible to still link to certain posts? For example, all posts that have the Taxonomy “linktopost” set to “on”.

    I tried to surround your filter with:

    if (is_tax('linktopost','on' )) {
    THE-FILTER
    }

    I also tried “term_exists” and “has_term” but it didn’t work, any idea what I did wrong?

    #922760
    Tom
    Lead Developer
    Lead Developer

    I think has_term() should work. Can you share your full code?

    #922793
    Sami

    Sure, this is the code I’ve used:

    if (has_term('linktopost','on' )) {
    add_filter( 'generate_featured_image_output', function( $output ) {
        return sprintf( // WPCS: XSS ok.
            '<div class="post-image">
                    %2$s
             </div>',
             esc_url( get_permalink() ),
             get_the_post_thumbnail(
                 get_the_ID(),
                 apply_filters( 'generate_page_header_default_size', 'full' ),
                 array(
                     'itemprop' => 'image',
                 )
             )
        );
    } );
    }
    #922797
    Leo
    Staff
    Customer Support

    What if you put the if statement inside?

    add_filter( 'generate_featured_image_output', function( $output ) {
        if (has_term('linktopost','on' )) {
        return sprintf( // WPCS: XSS ok.
            '<div class="post-image">
                    %2$s
             </div>',
             esc_url( get_permalink() ),
             get_the_post_thumbnail(
                 get_the_ID(),
                 apply_filters( 'generate_page_header_default_size', 'full' ),
                 array(
                     'itemprop' => 'image',
                 )
             )
        );
        }
        return $output;
    } );
    #923094
    Sami

    That worked πŸ™‚ Thank you for your help!

    #923418
    Leo
    Staff
    Customer Support

    No problem πŸ™‚

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