Getting Links in WordPress Comments to Open in a New Window

WordPress has gotten better over the years about seo and helping bloggers and site owners to build traffic, but it still has a couple of weaknesses.  One of the features that I am not fond of is how it opens links in comments in the same window.  If this bothers you too, here’s the solution…

First a hat tip to Adham who worked this out on a project we’re doing.

What you want to do is find the file wp-includes/formatting.php

and replace this line

return $matches[1] . “<a href=\”$url\” rel=\”nofollow\”>$url</a>” . $ret;

with

return $matches[1] . “<a href=\”$url\” rel=\”nofollow\” target=\”_blank\”>$url</a>” . $ret;

That’s it.  People can still click a link in the comment and go to that page, but now getting back to your fabulous content isn’t so difficult for them.

Categories: SEO Strategies Tags: comments, link attributes, link parameters, links, WordPress

5 Responses to “Getting Links in WordPress Comments to Open in a New WindowComment RSS feed

  • simon
    July 3rd, 2009 12:52 am
    #1

    sorry – doesn’t work :(

  • Dan
    January 6th, 2010 2:50 am
    #2

    Parse error: syntax error, unexpected T_STRING in /home/sites/dandragomir.biz/public_html/wp-includes/formatting.php on line 1294

    Wont work with target=”\blank\” eighter :(

  • jimmyj
    February 18th, 2010 3:56 pm
    #3

    doesn’t work…why keep this posted?

  • Will Craig
    June 8th, 2010 12:21 pm
    #4
  • PaulR
    November 14th, 2010 4:38 pm
    #5

    Thanks Will, it works great.
    People need to use their head because depending on your version of WP the code might be slightly different, but basically just need to add target=\”_blank\”.

    Will’s blog link above shows a more up to date version, it does work.