In WordPress, you can add Post Thumbnails in very easy way. Some WordPress Theme has this Post Thumbnails feature enabled by default.
However, the Post Thumbnails are just images, if you mouse over, they will show the image alt but by default, Post Thumbnails are not linked to the posts. After reading this tutorial, you will be able to Link Post Thumbnails to the Posts directly.
You can link Post Thumbnails to the Post Permalink in a specific loop or you can link all the Post Thumbnails on your WordPress Blog to the Post Permalink.
---
How to link Post Thumbnails to the Post Permalink in a specific loop
This loop will link Post Thumbnails only where they are applied. You might think to use this method when you want to link the Post Thumbnails in archival pages only. In other words, this code will link Post Thumbnails to the Post Permalink only in the Categories, Home, Tag pages if you add this to those / that (depends on theme) php files :
<?php if ( has_post_thumbnail()) : ?>
<a href=”<?php the_permalink(); ?>” title=”<?php the_title_attribute(); ?>” >
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
How to Link Post Thumbnails of your blog to the Post Permalinks for the whole blog
If you add this function to your current theme’s functions.php file, it will work for the whole blog:
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;}
Do not use both methods together to link post thumbnails. Thanks to WordPress Codex for the Link Post Thumbnails Function Reference.
