Archived topic
Remove linked Featured image, not image
11 replies · Started by Frode on October 25, 2016
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
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/
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
You're welcome :)
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.
To remove the featured image link on posts page?
This should work:
https://docs.generatepress.com/article/generate_featured_image_output/#example
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?
I think has_term() should work. Can you share your full code?
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',
)
)
);
} );
}
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;
} );
That worked :) Thank you for your help!
No problem :)