Automatically Link Featured Images to Posts - WPTRINITY

Automatically Link Featured Images to Posts

If your WordPress theme does not automatically link featured images to full articles, then you can try this method. Simply add this code to your theme’s functions file.

function wpe_autolink_featured_images( $html, $post_id, $post_image_id ) {
 
If (! is_singular()) { 
     
$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
return $html;
 
} else { 
 
return $html;
 
}
 
}
add_filter( 'post_thumbnail_html', 'wpe_autolink_featured_images', 10, 3 );