Most of the people are using WordPress as their blog platform. Here, I am going to share with you a small but useful trick to keep your visitors on your website.


WordPress Comment-Links in New Tab or New Window

New Tab or New Window

If you have good content in your blog post then the visitors will comment on your blog. Sometimes, the comment authors post links in their comments. If someone clicks a link in a comment, then by default WordPress opens it in the same window. So, there is a good chance of loosing a visitor.

It will be great if we could modify our blog behaviour such that to force comment-links in a different tab or different window of the browser. Read the simple solution provided below.


You will have to modify two files. First will force author link to open in new tab or window. Second will force links in comment-body to open in new tab or window.

Use double quotes and single quotes as they are given below. Any wrong modification will give fatal error, so be careful. You should copy and paste the codes below as they are, without modification.

  • Open this file : wp-includes/comment-template.php
    Find this line :
    $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
    Change it to :
    $return = "<a href='$url' rel='external nofollow' class='url' target='_blank'>$author</a>";
  • Open this file : wp-includes/formatting.php
    Find this line :
    return $matches[1] . "<a href=\"$url\" rel=\"nofollow\">$url</a>" . $suffix;
    Change it to :
    return $matches[1] . "<a href=\"$url\" rel=\"nofollow\" target=\"_blank\">$url</a>" . $suffix;
  • You are done. Check your WordPress blog to see the result. If you did everything correct then, every link (Author-link as well as comment-body-links) in every comment in your blog should now open in new tab or window. 🙂