How to Have Comment Links Open in a New Window with WordPress

So, people are starting to leave comments with their websites linked on the site.  Now this is all part of back linking and ways to get your own site seen by more people.  However, I wanted people to be able to click on their link without leaving my page.

So after searching and searching and trying many different ways that didn’t work, I finally found a page that had the answer.  Here is the simplified version:

In your WordPress admin page go to Appearance then select Editor

Next find your functions.php and add the following code:

// Make comment author link URL open in new window
function comment_author_link_window() {
global $comment;
$url = get_comment_author_url();
$author = get_comment_author();

if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "$author";
return $return;
}
add_filter('get_comment_author_link', 'comment_author_link_window');

I added the above code this right before the end of the functions.php, as in above the following:
/* End of file functions.php */
/* Location: ./functions.php */

It works great for me.

JD

// Make comment author link URL open in new window

function comment_author_link_window() {

global $comment;

$url = get_comment_author_url();

$author = get_comment_author();

if ( empty( $url ) || ‘http://’ == $url )

$return = $author;

else

$return = “<a href=’$url’ rel=’external nofollow’ target=’_blank’>$author</a>”;

return $return;

}

add_filter(‘get_comment_author_link’, ‘comment_author_link_window’);

To share this article with others, just click on your social media below:
  • Print
  • Twitter
  • Digg
  • del.icio.us
  • StumbleUpon
  • Facebook
  • Tumblr
  • LinkedIn
  • Sphinn
  • Mixx
  • Google Bookmarks
  • Blogplay

Subscribe Today

Enter Your Email to Keep Up-to-Date with the Latest Blog Posts

Delivered by FeedBurner

Donations

If you found this article or tips helpful and would like to say thank you in the form of a donation or perhaps buy me a cup of coffee or a beer, then please use the form below and Thank you so very much.

Please Select a Beverage Below

About JD

John Howard has owned 13 companies, had a Real Estate license, been an Mortgage Loan Officer, been extensively involved in Day Trading, Commodities, Bought and Sold Tax Property, Accomplished Tax Auditor, Accountant, Written numerous computer programs, Written Screen Plays & Short Films, been Director on two major production short films, and has been semi-retired since 2007, concentrating on personal investing and writing.