Support » Fixing WordPress » Auto-add target="_blank" and rel="nofollow" to links?

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi,
    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…

    I never say never 😀

    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?

    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…

    Moderator Andrew Nevins


    Forum moderator

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

    Are you using WordPress version 3?

    Andrew, yes, I’m currently on 3.5.2.

    jnhghy, thanks for that jquery!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Auto-add target="_blank" and rel="nofollow" to links?’ is closed to new replies.