Hello All,
I'm trying to link my post images (which I display on my homepage) to link to the URL that the user inputs into the Link URL section when setting a featured image.
So for example, I upload and set a featured image and then I enter a custom URL and click on set as featured image. Then whenever a user clicks on the image they are taken to the link URL entered when they set the featured image.
I've tried to resolve this myself before posting, I know the following code successfully links the featured image to the post permalink and therefore the post itself, but not a custom URL as I'd ideally like it:
// Link post thumbnails to 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;
}
I tried replacing get_permalink( $post_id ) with:
wp_get_attachment_thumb_url( $post_id )
But it didn 't work. If any folks have ideas it would be greatly appreciated!
Thanks!