Support » Fixing WordPress » 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; – eg. featured post = mananation’s – when you click on the image while on the frontpage – you directly get redirected to

    Anyone care to help me out here?

    I would be mighty grateful… 🙂

    Kind regards

Viewing 15 replies - 1 through 15 (of 19 total)
  • no, i’m having the same question. Been trying different approaches, but no luck…

    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 checking if the_content exists for theme structure…I think a modified version of this *could* work…seeing what I can come up with. 🙂

    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!

    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(); ?>
    					<?php } else { ?>
    					<a href="<?php $key="featured_external"; echo get_post_meta($post->ID, $key, true); ?>" title="<?php the_title(); ?>">
    					<?php the_post_thumbnail(); ?>
    					<?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 : )

    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. 🙂


    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

    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(); ?>

    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

    Thank you kind sir! ; )

    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?

    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!


    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);

    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!

    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.

    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?

    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”>


    <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’); ?>
    <?php } else { ?>
    <a href=”<?php $key=”featured_external”; echo get_post_meta($post->ID, $key, true); ?>” title=”<?php the_title(); ?>”>
    <?php the_post_thumbnail(); ?>
    <?php } ?>
    <?php } ?>

    <?php endwhile;?>
    <!– END –></div><!–apparel–>


Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Featured Image Link’ is closed to new replies.