Monday, January 4, 2010

The importance of making your Wordpress author comment urls open in a new window and the code to make it happen

(My Original Blog Post: http://ping.fm/EViBn)
Comment cloud with a pencil over it.When I first noticed that my author comment urls were opening in the same window as my blog, I kind of got annoyed by this. Why? Because I don't want people leaving my blog completely to visit a comment author's site. Instead, I don't mind them visiting a comment author's blog as long as my blog is still open in one of their browser windows.

This, simply put, is the main reason why you wouldn't want visitors to leave your site completely. Unfortunately, most Wordpress blog theme templates don't set this up for you automatically. If you're not sure if yours does, just go to one of your single posts and click on one of your comment author links. If it removes your blog completely from the browser, then you don't have the target="_blank" attribute set up properly.

Thankfully, I came across a really cool site that explains exactly how to set up your Wordpress theme's function.php file to open comment author links in a new window.

If you're not concerned about all the ins and outs of how to accomplish this, just follow these instructions:

Once logged into your Wordpress admin area, go to Appearance, then Editor. Once there, find your functions.php file. Click on it, and simply paste the following php code at the bottom of the file before the php closing tag (looks like this "?>".


// 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');


Hope this code is of use to you.

0 comments:

Post a Comment