Title: Featured Image Link
Last modified: August 19, 2016

---

# Featured Image Link

 *  [arcum](https://wordpress.org/support/users/arcum/)
 * (@arcum)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/featured-image-link/)
 * Hi,
 * I was wondering, when I make a new post with a featured image attached to it,
   I can make the image clickable with a url of my choice.
    So, now I want my featured
   posts on my frontpage to link directly to the url I’ve attached to my image (
   of that featured post)… Because right now people have got to click on the image,
   going to the post, and have to click again on that image to go to the site mentioned.
 * Check my site to help visualize things a little; [http://www.mtgfeeds.com](http://www.mtgfeeds.com)–
   eg. featured post = mananation’s – when you click on the image while on the frontpage–
   you directly get redirected to mananation.com
 * Anyone care to help me out here?
 * I would be mighty grateful… 🙂
 * Kind regards

Viewing 15 replies - 1 through 15 (of 19 total)

1 [2](https://wordpress.org/support/topic/featured-image-link/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/featured-image-link/page/2/?output_format=md)

 *  [MartinLeclercq](https://wordpress.org/support/users/martinleclercq/)
 * (@martinleclercq)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629164)
 * no, i’m having the same question. Been trying different approaches, but no luck…
 *  [lovduv](https://wordpress.org/support/users/lovduv/)
 * (@lovduv)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629178)
 * I am trying to do this as well…I will post if I find anything.
 * Here is what I have currently and what I want to do…
 * Using a “featured” slideshow on home page that pulls images and captions from
   my “featured” category and displays both in the slideshow. I would like to use
   external as well as internal links i.e if I have a post that corresponds with
   the image than it will link to the post…if there is no content then it will use
   the link url in settings….barring an easier solution…I see it working by using
   an if statement to check for the existence of content then if content exists 
   use post url else if none use the link url set in the image properties…trying
   to find out now how wordpress calls the set link for an insert post maybe that
   will shed some light
 * This post discusses [http://www.doc4design.com/articles/if-content-exists/](http://www.doc4design.com/articles/if-content-exists/)
   checking if the_content exists for theme structure…I think a modified version
   of this *could* work…seeing what I can come up with. 🙂
 *  [lovduv](https://wordpress.org/support/users/lovduv/)
 * (@lovduv)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629179)
 * Ok definitely think this is possible using custom fields…set the field with the
   url, then use the if/else statement for link…working on it!
 *  [lovduv](https://wordpress.org/support/users/lovduv/)
 * (@lovduv)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629180)
 * Ok I did it 🙂
 * So here is what I did:
 * I added a custom field called “featured_external” for name and then I put the
   url I want to link to in for value.
 * Then I added this chunk of code where I want my featured images to show…This 
   works because I test for the existence of content in the post…so for it to work
   you must set the featured image and have NO content…one word in the post and 
   your image will link to the post…There may be a better more elegant way to do
   this, but it worked for me…
 *     ```
       <?php query_posts( 'cat=Featured&posts_per_page=5' ); if( have_posts() ) : while( have_posts() ) : the_post(); ?>
       <?php $key="featured_external"; $custom = get_post_meta($post->ID, $key, true); ?>
   
       	<?php if(has_post_thumbnail()) {
       			if($content = $post->post_content ) { ?>
       				<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
       				<?php the_post_thumbnail(); ?>
       				</a>
       					<?php } else { ?>
       					<a href="<?php $key="featured_external"; echo get_post_meta($post->ID, $key, true); ?>" title="<?php the_title(); ?>">
       					<?php the_post_thumbnail(); ?>
       					</a>
       					<?php }  ?>
       	<?php }  ?>
       	<?php endwhile; endif;?>
       ```
   
 * Now this works for MY theme which has a slideshow with the most recent 5 posts,
   you will need to adapt for yours but this example should get you there : )
 *  [ceopowertools](https://wordpress.org/support/users/ceopowertools/)
 * (@ceopowertools)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629218)
 * Okay lovduv,
 * Are you interested in hiring out to do it for me? 🙂 I need this as well but 
   am a real novice when it comes to code stuff. I wonder why nobody has built a
   plugin for this yet?!?! Maybe that isn’t an option and I’m just showing how naive
   I am. 🙂
 *  [lovduv](https://wordpress.org/support/users/lovduv/)
 * (@lovduv)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629219)
 * Hi,
 * Sure, but depending on the complexity of what you need (i.e if it’s easy), I 
   may just do it for free, cuz I am awesome like that…lol…
 * Send me an email with your url and what exactly you are trying to accomplish 
   and we will go from there… support at achievementwebsolutions dot com
 *  [lovduv](https://wordpress.org/support/users/lovduv/)
 * (@lovduv)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629221)
 * I worked out ceopowertools request…he needed something a bit different, but what
   I did discover in working on his…all you really need to accomplish an external
   link on a featured image is two of the above lines from there you can be as complex
   or as simple as you want. : )
 * This will pull your link from the custom field “featured_external”:
    `<?php $
   key="featured_external"; $custom = get_post_meta($post->ID, $key, true); ?>`
 * This will create the link when wrapped around wherever you call the featured 
   image:
 *     ```
       <a>ID, $key, true); ?>" title="<?php the_title(); ?>">
       <?php the_post_thumbnail(); ?>
       </a>
       ```
   
 *  [ceopowertools](https://wordpress.org/support/users/ceopowertools/)
 * (@ceopowertools)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629222)
 * **WOW!!!** I can’t say enough thank-you’s to lovdov! She made short work of the
   problem that had been driving me (and my wife) crazy for a couple of weeks! I
   HIGHLY recommend her to anyone building something with WordPress! She even took
   the time and effort to send me some security tips for my site that weren’t part
   of what she was working on. I will definitely be hiring her in the future. Thanks
   a million for my life MUCH better!
 * CEO Powertools
 *  [lovduv](https://wordpress.org/support/users/lovduv/)
 * (@lovduv)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629223)
 * Thank you kind sir! ; )
 *  [stevestavstav](https://wordpress.org/support/users/stevestavstav/)
 * (@stevestavstav)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629267)
 * Hey, I’m having the same issue and this seems to be the most informative solution
   I’ve come across. I’ve been at this for weeks! Basically, what I’m trying to 
   do is get the featured images on my homepage to link to another url besides the
   post itself. I hope to set a youtube link as that url so the featured image opens
   in lightbox as a video within the page. My first stab at making that happen is
   actually being able to set the featured image to link somehwere other than the
   full post. creating a custom field seems like the way to go. Lovduv, where would
   I place those codes? index.php?
 *  [pacuthbert](https://wordpress.org/support/users/pacuthbert/)
 * (@pacuthbert)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629271)
 * Hi Lovduv,
    This is probably a delayed one as well and much appreciated for the
   solution!
 * I think I get it, but I was wondering where in the code would you put the custom
   link where you actually force the link to the image? I hope that made some sense!
 * Thank you again!
 * Cheers,
    Ashley
 *  [the1path](https://wordpress.org/support/users/the1path/)
 * (@the1path)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629274)
 * Hi all this was almost what I needed but because I was working with a custom 
   theme the “Featured Image” was not attached to a post but to a custom built “
   Link Widget”. Basically I lacked the ability to create a custom field for the
   url. So I found another solution which others might adapt, learn from or indeed
   find easier!
 * What I did was put the url I wanted in the description area when you add a Featured
   Image. Just pasted it straight in there! Then I …
 * Setup the arguments to use with the current post using the current post id (i
   used a custom variable $number) and put in an array
    `$at_args = array( 'post_type'
   => 'attachment', 'post_parent' => $number );` /* please not Ive used $number 
   but you may want to use $post->ID as this was a custom function I was using */
 * Use the array of arguments use the get_posts() function to get attachment ID 
   data
    `$attachment_data = get_posts( $at_args );`
 * You cant use the ID by default with get_posts() so we must call setup_postdata()
   and loop through each array item
 *     ```
       foreach( $attachment_data as $post ) : setup_postdata($post);
       endforeach;
       ```
   
 * Stick the attachment ID in a variable
    `$attachment_id = $attachment_data->ID;`
 * Use the get_post function to call in an array of post data with the corresponding
   ID (attachment)
    `$link = get_post( $attachment_id );`
 * Then finally to display the damn url
    `<a href="<?php echo $link->post_content;?
   >">whatever</a>`
 * Hmmm once I right it down it doesnt look easier but may help someone!
 *  [DHebe](https://wordpress.org/support/users/dhebe/)
 * (@dhebe)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629275)
 * the easiest way I found is to go to media where the picture is stored
    or edit
   image. Wipe out the link url and put in your own, click update. You can also 
   just put the url of your choice in as son as up upload the image.
 *  [IAMTHELAB](https://wordpress.org/support/users/faberuna/)
 * (@faberuna)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629276)
 * lovduv or to any of you talented folks:
 * Where would I put the code you suggest? I get the part where you add a custom
   field to the post but not where to put the code to make it work. Any suggestions?
 *  [resonant705](https://wordpress.org/support/users/resonant705/)
 * (@resonant705)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/featured-image-link/#post-1629277)
 * having a little bit of trouble with having the title permalink link to the featured
   external link. The thumbnail works nicely but can’t get the text to match the
   featured external url
    below is the code I used `<!–section_apparel–> <div class
   =”section”> <div class=”site_title” id=”apparel_site_title”><a name=”APPAREL”
   ><img src=”<?php bloginfo (‘template_directory’); ?>/images/title_apparel.png”/
   ></a> </div><!–site_title–> <div id=”apparel”><?php query_posts(‘cat=6&showposts
   =-1’); ?> <?php while (have_posts()) : the_post(); ?> <?php $key=”featured_external”;
   $custom = get_post_meta($post->ID, $key, true); ?> <div class=”latest-post-wrap”
   > <div class=”latest-post”> <div class=”latest-title”> <h2>
 * </h2>
    </div>
 *  <div class=”feat-thumb”>
 *  <?php if(has_post_thumbnail()) {
    if($content = $post->post_content ) { ?> <
   a href=”<?php the_permalink(); ?>” title=”<?php the_title(); ?>”> <?php the_post_thumbnail(‘
   feat-loop2’); ?> </a> <?php } else { ?> <a href=”<?php $key=”featured_external”;
   echo get_post_meta($post->ID, $key, true); ?>” title=”<?php the_title(); ?>”>
   <?php the_post_thumbnail(); ?> </a> <?php } ?> <?php } ?> </div> </div>
 *  </div>
    <?php endwhile;?> <!– END –></div><!–apparel–> </div><!–section_apparel–
   >`
 * cheers
    nate

Viewing 15 replies - 1 through 15 (of 19 total)

1 [2](https://wordpress.org/support/topic/featured-image-link/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/featured-image-link/page/2/?output_format=md)

The topic ‘Featured Image Link’ is closed to new replies.

## Tags

 * [link](https://wordpress.org/support/topic-tag/link/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 19 replies
 * 10 participants
 * Last reply from: [IAMTHELAB](https://wordpress.org/support/users/faberuna/)
 * Last activity: [14 years, 7 months ago](https://wordpress.org/support/topic/featured-image-link/page/2/#post-1629281)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
