[Resolved] Any way at all of making the featured image a link to its media file in posts?

Home Forums Support Any way at all of making the featured image a link to its media file in posts?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1156495
    Michael

    So I’d like to show the featured image in a certain category of posts (elsewhere it is in the header). But ideally, due to the nature of the posts, I’d like users to be able to click the featured image so my lightbox will show it larger.

    Possible at all?

    #1156717
    David
    Staff

    Hi there,

    try this PHP snippet:

    add_filter( 'post_thumbnail_html', 'db_post_thumb_media_link', 10, 3 );
     
    function db_post_thumb_media_link( $html, $post_id, $post_image_id ) {
    
        if ( !is_single() ) {
            // Return default if NOT single
            return $html;      
        } else {
            // Get URL of large image attachment
            $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
            // Wrap HTML in link
            $html = '<a href="' . $large_image_url[0] . '">' . $html . '</a>';
            return $html;
        }
    }
    #1157019
    Michael

    Thanks very much David, I didn’t think it was going to be possible.

    You guys rule!

    #1157534
    David
    Staff
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.