post

Make Post Thumbnails Link to Post Page

Make WordPress post thumbnail images link to the single post page

I started a new project several weeks ago and one of the design elements on that site is a WordPress Post Thumbnail “teaser” on the home page, along with a larger version on the single post page. It only made sense to make these home page teaser images hyperlink to the single post page, and fortunately I found a quick-and-easy solution in the WordPress Support Forums.

// THIS LINKS THE THUMBNAIL TO THE POST PERMALINK

add_filter( 'post_thumbnail_html', 'my_post_image_html', 10, 3 );

function my_post_image_html( $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;
}

You can find the original thread here. Dropping this code into the funtions.php file automagically hyperlinks all of the post thumbnail images to their respective single post pages.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>