Forums

[resolved] Retrieve the link url for the thumbnail (3 posts)

  1. Christine
    Moderator
    Posted 1 year ago #

    hi there,
    I'm using the following code inside my loop to display portfolio images:

    <a href="<?php wp_get_attachment_thumb_url( get_post_thumbnail_id( $post->ID ) ); ?>"><?php the_post_thumbnail( 'single-post-thumbnail' ); ?></a>

    The image appears fine, but I can't retrieve the link url. The code <?php wp_get_attachment_thumb_url( get_post_thumbnail_id( $post->ID ) ); ?> is obviously wrong.

    Anyone know what it should be?

  2. CatherineWinters
    Member
    Posted 1 year ago #

    Sure, try this:
    <a href="<?php print wp_get_attachment_thumb_url( get_post_thumbnail_id( $post->ID ) ); ?>"><?php the_post_thumbnail( 'single-post-thumbnail' ); ?></a>

    wp_get_attachment_thumb_url() just returns the resulting URL; it doesn't actually do anything with it. To get it to print out, you need to use print.

  3. Christine
    Moderator
    Posted 1 year ago #

    I managed to get the url, but it won't keep my external link. Instead it uses the link to the attachment. I gave up and in the end, just used a custom field.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.