Deluxe Blog Tips About Projects

Auto Link Thumbnails To Posts In WordPress

Post thumbnails are usually displayed big in archive pages and people tend to click on them to navigate to posts rather than clicking on post titles. So make post thumbnails link to the posts can help your users have better experience, thus improve website friendliness.

This simple code above will help you do that, put it in the functions.php file of your theme, or better, in a file that optimized for loading in front-end only.

add_filter( 'post_thumbnail_html', 'rw_post_thumbnail_html', 10, 2 );
function rw_post_thumbnail_html( $html, $post_id )
{
    $html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
    return $html;
}

Subscribe to the Newsletter

Subscribe to get my latest content by email. I won't send you spam. Unsubscribe at any time.