[resolved] custom link for featured image (13 posts)

  1. jrcollins
    Posted 2 years ago #

    I've done a lot of searching but can't seem to find anything about how to do this. I want to create a custom field that will attach a link to the featured image.

  2. Hi @jrcollins,

    I hope you are well today and thank you for your question.

    You can use this free plugin http://premium.wpmudev.org/forums/topic/how-can-i-add-an-external-url-link-to-a-featured-image#post-540709 to attach a custom link from custom field to the featured image.

    You can also use this paid plugin http://epicplugins.com/external-url-link-to-featured-images/ to achieve the same.


  3. jrcollins
    Posted 2 years ago #

    Hi, thanks for your suggestion but I don't think that's quite what I'm looking for.

    That first plugin is for changing the post title permalink to a custom url and the second one "...allows you to set your post thumbnail (featured image) from an external URL without uploading the image to your WordPress media library."

    I want to have featured images link to a custom url. I thought it would be possible to do this by creating a custom field and then calling up that variable in the code for the featured image. Unfortunately I still have only a very basic knowledge of php and I'm not confident enough to attempt this on my own.

  4. Andrew Nevins
    Forum moderator
    Posted 2 years ago #

    Edit: NVM duplicate thread.

  5. Hi @jrcollins,

    Thanks for reply.

    You can just create custom field having name/key external_link_key and display it using following code.

    <?php $key="external_link_key"; $single=1; $external_link = get_post_meta($post->ID, $key, $single); ?>  
    <?php if($external_link == ""){ ?>
    	<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> <?php the_post_thumbnail(); ?></a> <?php ;}
    else{ ?>
    	<a href="<?php echo $external_link; ?>" title="<?php the_title(); ?>"> <?php the_post_thumbnail(); ?></a> <?php } ?>

    Best Regards,

  6. jrcollins
    Posted 2 years ago #

    Hi, thanks for your input. I found your code to be overly complicated and in the end used the following simpler code:

    <?php $name = get_post_meta($post->ID, 'ExternalUrl', true);
    if( $name ) { ?>
    <a href="<?php echo $name; ?>"><?php the_post_thumbnail(); ?></a>
    <?php } else {
    } ?>

    Thanks for your help!

  7. Hi @jrcollins,

    You are welcome.

    The provided code looks complicated because i have declared function parameters as variables so that you can can change it, added link for normal thumbnails and also added title attribute to the anchor so that a tool tip will be displayed on hovering the link text but if you don't need this then you can remove it as you have done so.

    I liked that you have made code simpler.


  8. hehafner
    Posted 2 years ago #

    @WPMU DEV Can you please clarify where this snippet of code would go?

    I want to link my individual featured images to external sites such as Amazon. I'm not importing the image from Amazon, but sending customer to Amazon via the link on the image.

    I assume that's what this thread is for.


  9. jrcollins
    Posted 2 years ago #

    That should be in your single post template file or wherever featured images appear. Just find and replace the code. You will also need to create a custom field.

  10. Hi @hehafner,

    Greetings and thanks for posting on the forums.

    @jrcollins has answered you very well in his last reply.

    Please advise if you have more questions.

    Best Regards,

  11. lvisage
    Posted 2 years ago #

    I have been looking for such a plugin. is there one? since I can not figure out the code especially if I have to insert and configure it for every single featured image.

    thanks much

  12. Hi @lvisage,

    You can develop a small plugin using the plugin code posted in the following reply.



  13. hehafner
    Posted 2 years ago #

    I found an excellent plugin for featured images. However, don't know if it works for all themes. It works for Thesis Themes. It is "Extended WordPress Featured Image," by Serge Liatko. I've been using if for about a week or two and it does the trick. You can link the images to external websites as well as resize the feature image if you need to.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.