WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] custom link for featured image

[Resolved] custom link for featured image

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

Viewing 12 replies - 1 through 12 (of 12 total)
  • 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.

    Cheers.

    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.

    Moderator Andrew Nevins

    @anevins

    Edit: NVM duplicate thread.

    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,

    jrcollins

    @jrcollins

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

    Thanks for your help!

    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.

    Cheers.

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

    TIA!

    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.

    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,
    WPMU DEV

    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

    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.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] custom link for featured image’ is closed to new replies.
Skip to toolbar