Opening WordPress Comment Author URLs In A New Window
Posted: June 10th, 2010 | Author: kn00tcn | Filed under: Tips/TutorialsTags: php, url, web, wordpress
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; } ?>
Save it as a PHP file, then upload to your WP plugins directory and enable the ‘Edit Comment Author’ plugin.
Last Modified: June 10th, 20103 Comments »


i think i saw that on technorati yesterday
Hi there
Definitely gonna recommend this post to a few friends
Hi – I am definitely glad to find this. Good job!