/**
* Link all post thumbnails to the post permalink.
*
* @param string $html Post thumbnail HTML.
* @param int $post_id Post ID.
* @param int $post_image_id Post image ID.
* @return string Filtered post image HTML.
*/
function wpdocs_post_image_html( $html, $post_id, $post_image_id ) {
$html = '<a href="' . get_permalink( $post_id ) . '" alt="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
return $html;
}
add_filter( 'post_thumbnail_html', 'wpdocs_post_image_html', 10, 3 );
Quelle: https://developer.wordpress.org/reference/functions/the_post_thumbnail/