Auto-add target="_blank" and rel="nofollow" to links? (6 posts)

  1. Shyzer
    Posted 2 years ago #

    Back in WordPress 2.X, I was able to edit line 369 of the quicktags.js file to read as follows:

    edButtons[i].tagStart = '<a href="' + URL + '" target="_blank" rel="nofollow">';

    This allowed me to automatically, by default, include target="_blank" and rel="nofollow" in all my links.

    Unfortunatly I can't seem to replicate this fix in WordPress 3. I edited the following line of the dev file to this:

    t.tagStart = '<a href="' + URL + '" target="_blank" rel="nofollow">';

    But that didn't produce the desired result. Any ideas?

    And before anybody says anything, I know automatically opening in new windows is frowned upon, but it's what my users want and it works best for this one individual site.

  2. jnhghy
    Posted 2 years ago #

    you said you know that automatically opening in new widow is frowned upon...but did you know that you never should modify framework files?
    ok, nevermind that. The solution that I'm thinking at for this is to set up a jquery in the header of your site that will add the target="_blank" for all the links, just google how you can do that, you will get a lot of hits. this way you don't modify any wordpress core files...

  3. Shyzer
    Posted 2 years ago #

    I never say never :D

    Yes, yes, I know hacking away at core files is frowned upon, but I've done it in this case for almost 4 years and it works wonders. Up until now it's been much easier to keep a modified quicktags file on hand and change it in each WP release than it has been to get a custom plugin developed for this or adding more code to my site.

    Thanks for your suggestion though.

    Any other ideas?

  4. jnhghy
    Posted 2 years ago #

    Haven't tested this but it should work... all you have to do you need to add this jquery to the header:

      $('a').attr('target', '_blank');

    if this jquery doesn't select the "a" tag then javascript will do:

    window.onload = function(){
    var anchors = getElementsByTagName('a');
    for (var i=0; i<anchors.length; i++){
        anchors[i].setAttribute('target', '_blank');

    and that's it.... from here on you can just update wordpress without having anything alse to do...

  5. Andrew Nevins
    Forum moderator
    Posted 2 years ago #

    Unfortunatly I can't seem to replicate this fix in WordPress 3.

    Are you using WordPress version 3?

  6. Shyzer
    Posted 2 years ago #

    Andrew, yes, I'm currently on 3.5.2.

    jnhghy, thanks for that jquery!

Topic Closed

This topic has been closed to new replies.

About this Topic