Auto Link Featured Post Thumbnails to The Post Permalink


Without any doubts, featured post thumbnails are one of the best features of WordPress. That’s why we are always trying to customize them and use them in unique ways on WordPress websites. For example, in previous articles we posted about how to add featured post thumbnails into blog RSS feeds, create an intuitive image based post navigation and automatically pull first image from post content to use as featured image for an article. And now in this article we will show you how to link all post thumbnails to the post permalink without you having to change each post individually.

To do that we will modify the HTML output of featured post thumbnails with the WordPress filter post_thumbnail_html. We will add post permalink into the HTML output, so all post thumbnails will automatically link to the posts. We have created a small function for you to use.

Adding this WordPress snippet to the functions.php of your WordPress theme will automatically link all post thumbnails to the post permalink. It’s as easy as that.

// auto link featured post thumbnails to the post permalink
function wcs_auto_link_post_thumbnails( $html, $post_id, $post_image_id ) {
    $html="<a href="" . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
    return $html;
add_filter( 'post_thumbnail_html', 'wcs_auto_link_post_thumbnails', 10, 3 );

Leave a Reply

Random Post Selection ::

Recent Posts

Unlock Unlimited Downloads