Link Featured Images to Their Post
Wraps featured images in archive and feed contexts with an anchor tag that links to the post permalink, so thumbnails are clickable.
PHPby SnipCraft
php
<?php
if ( ! function_exists( 'scseed_link_post_thumbnail' ) ) {
function scseed_link_post_thumbnail( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
// Don't wrap on singular views — image is already in context
if ( is_singular() || empty( $html ) ) {
return $html;
}
$permalink = get_permalink( $post_id );
$title = esc_attr( get_the_title( $post_id ) );
return '<a href="' . esc_url( $permalink ) . '" title="' . $title . '" tabindex="-1" aria-hidden="true">'
. $html . '</a>';
}
add_filter( 'post_thumbnail_html', 'scseed_link_post_thumbnail', 10, 5 );
}#display#featured-image#link#template#thumbnail