WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. jrcollins
    Member
    Posted 9 months 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. WPMU DEV
    Member
    Posted 9 months ago #

    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.

  3. jrcollins
    Member
    Posted 9 months 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
    Forum Moderator
    Posted 9 months ago #

    Edit: NVM duplicate thread.

  5. WPMU DEV
    Member
    Posted 9 months ago #

    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
    Member
    Posted 9 months 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 {
    the_post_thumbnail();
    } ?>

    Thanks for your help!

  7. WPMU DEV
    Member
    Posted 9 months ago #

    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.

  8. hehafner
    Member
    Posted 2 months 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.

    TIA!

  9. jrcollins
    Member
    Posted 2 months 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. WPMU DEV
    Member
    Posted 2 months ago #

    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

  11. lvisage
    Member
    Posted 1 month 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. WPMU DEV
    Member
    Posted 1 month ago #

    Hi @lvisage,

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

    http://premium.wpmudev.org/forums/topic/how-can-i-add-an-external-url-link-to-a-featured-image#post-540709

    Cheers,
    WPMU DEV

  13. hehafner
    Member
    Posted 1 month 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.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.