I have a custom field that contains links in them and I want to auto add nofollow to those links in that custom field only. How can I do this?

Example custom field value:

<a href="http://www.uploadable.ch/file/PnvbZ2k8B4ku/[Raizel]_Medaka_Box_01v2_(BD_720p_AAC)_(1A92BFA4).mkv">[Raizel]_Medaka_Box_01v2_(BD_720p_AAC)_(1A92BFA4).mkv</a>

I found a tutorial that auto adds nofollow to externals link http://smartwebworker.com/485-automatic-nofollow-external-links-wordpress/ but it only applies to post content and not custom field. Anyone know a way to make it work with custom fields?

2 Answers 2


This is something you cannot change in the field it self, but in the template file. Copy and paste here the template file where this option is outputted.

Another way will be to add a javascript snippet to you head, if you have such option in you template.

Comment here and we'll see what the best solution is.


I think best solution for you is to use 2 different custom fields - one for the url (call it Links, but put only the url and not the full html link) and one for the link title (call it Links_title, and put just the text you want to be linked). Then put this code in your template to output it:

    <a href="<?php echo( get_post_meta( $post->ID, "Links", true ) ); ?>" title=" <?php echo( get_post_meta( $post->ID, "Links_title", true ) ); ?>" rel="nofollow">
     <?php echo( get_post_meta( $post->ID, "Links_title", true ) ); ?>
  • I just use <?php echo get_post_meta($post->ID, "Links", true); ?> to output the custom field. The value of the custom field are already html coded links. So How would I actually do it with javascript?
    – Ruriko
    Commented Mar 7, 2015 at 10:18
  • do you need to have the ability to change other <a> attributes? like target or title? please paste here the value you put in the custom field and i'll try to help you with upgrading it.
    – Ituk
    Commented Mar 7, 2015 at 11:24
  • No I don't need to change other attributes. All I want is add nofollow. I've edited my post to add example value.
    – Ruriko
    Commented Mar 7, 2015 at 11:59
  • Okay, see update in my answer.
    – Ituk
    Commented Mar 7, 2015 at 18:55
  • The only problem is your solution is this will not work with existing posts that have full html link in custom field. Any other methods?
    – Ruriko
    Commented Mar 7, 2015 at 23:37

(I can't comment for being 50- reputation) I didn't understand your problem well. Choose or tell us;

1) Your post content have links and you want to add nofollow to links in custom fields which already used in content

2) You're writing your custom field's value already but just want to add nofollow.

or tell us your scenario


<a href="<?php echo( get_post_meta( $post->ID, "Links", true ) ); ?>" rel="nofollow">
     <?php echo( get_post_meta( $post->ID, "Links", true ) ); ?>

is this what you need ?

  • All I want is auto add nofollow when displaying links from the custom field
    – Ruriko
    Commented Mar 7, 2015 at 12:40
  • Updated, please check
    – ahmetertem
    Commented Mar 7, 2015 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.