Site logo

Archived topic

Blog archive page: featured images linking

7 replies · Started by ch1800 on July 25, 2020

Viewing posts 1–8 of 8

Hi folks,

Blog archive page: Is there a way to link the post's featured image + the page title to the media (lightbox) instead of the corresponding blog page?

PS: I'm already using this for randomizing them.

Thanks and happy Sunday!

Hi there,

You'd have to set up the lightbox part, but you may be able to filter the link of the featured image/title like this:

add_filter( 'post_link', function( $link ) {
    if ( ! is_singular() && has_post_thumbnail() ) {
        return get_the_post_thumbnail_url();
    }

    return $link;
} );

Let me know :)

Excellent, works like a charm!
Many thanks for this and the previous one for randomizing them that I also found here.

I use those for creating a design portfolio, simply by using GP's masonry layout for posts archives. No need of another plugin. Featured images are design screenshots in full height and details & links to the websites are in the excerpts.

Awesome, glad it worked! :)

Hi again about same topic: I would like to use the same snippet above that works fine for "all posts" but by adding a condition to apply only to a given post category, ex. all posts from category "abcd".

Would this be possible?

Thanks!

Hi there,

try changing:

if ( ! is_singular() && has_post_thumbnail() ) {

to:

if ( ! is_singular() && has_post_thumbnail() && has_category('your-category') ) {

Great, many thanks for your help!

You're welcome

This archived topic is closed to new replies.