ThemeShaper Forums » Thematic


Link Post to Featured Image Link URL

(2 posts)
  • Started 7 years ago by proto
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. proto

    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!


    Posted 7 years ago #
  2. try:

    $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ) );

    Posted 7 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.