Auto link post thumbnails to the post permalink

Adding this code to the functions.php of your wordpress theme will Automatically link all post thumbnails to the post permalink.

 

 

add_filter( 'post_thumbnail_html', 'wps_post_thumbnail', 10, 3 );
function wps_post_thumbnail( $html, $post_id, $post_image_id ) {
$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_post_field( 'post_title', $post_id ) ) . '">' . $html . '</a>';
return $html;
}

Leave a comment