Opening WordPress Comment Author URLs In A New Window

Posted: June 10th, 2010 | Author: | Filed under: Tips/Tutorials
Tags: , , ,

Here’s a short tip on how to add target=”_blank” to the HTML code generated by WordPress’s comment_author_link(). I can’t seem to get it to work as a filter inside comments.php, but I found a forum post that does what’s needed as a WP plugin. Apparently it needs WP2.5 and up. The simplest way would be modifying the core WP files, but that’s a bad idea due to any updates overwriting your changes, making you do them over again.

<?php
/*
Plugin Name: Edit Comment Author
Version: 0.1
Description: Automatically adds target="_blank" to comment author links
Author: Jay Gilford
Author URI: http://www.jaygilford.com/
Plugin URI: http://www.jaygilford.com/
*/
global $wp_version;
$exit_message = 'This plugin requires Wordpress 2.5 or newer. <a href="http://codex.wordpress.org/Upgrading_WordPress">Please Update!</a>';
if(version_compare($wp_version, '2.5', '<')) {
	exit($exit_message);
}
 
add_filter('get_comment_author_link', 'comment_author_link_edit');
function comment_author_link_edit($content) {
    $content = str_replace('<a ', '<a target="_blank"', $content);
    return $content;
}
?>

Source

Save it as a PHP file, then upload to your WP plugins directory and enable the ‘Edit Comment Author’ plugin.

Last Modified: June 10th, 2010

3 Comments »

3 Comments on “Opening WordPress Comment Author URLs In A New Window”

  1. 1 HiepSoype said at 3:47 pm on September 12th, 2010:

    i think i saw that on technorati yesterday

  2. 2 Jamie Iomo said at 8:51 pm on December 7th, 2010:

    Hi there

    Definitely gonna recommend this post to a few friends

  3. 3 AswadKannal said at 12:58 pm on May 23rd, 2011:

    Hi – I am definitely glad to find this. Good job!


Leave a Reply