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.
sorry – doesn’t work
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
doesn’t work…why keep this posted?
I have written instructions how to do this on my blog:
http://www.willwebdeveloper.com/2010/06/open-comment-authors-website-link-in-a-new-window/
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.