
Post images (without permalink) link to the Post Permalink
WordPress PHP – To make orphaned post images (without a permalink) link to the Post Permalink put the code below into your functions.php.
This code reproduced from a post by Barbara Ford on WordPress.org here > (External link).
Put this code into the theme’s functions.php . This will make nearly all images link through to your news/post section.
* 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 = ‘‘ . $html . ‘‘;
return $html;
}
add_filter( ‘post_thumbnail_html’, ‘wpdocs_post_image_html’, 10, 3 );
Alternatively, to target a single template use the code below (from the same source) and place in the theme’s template (usually the post loop of your content.php)
Note: Don’t use both examples in the same theme
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
Done.
Fivepilchard Team