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.
Related Posts:
- How to know who you should and shouldn’t follow on Twitter
- Properly set up your WordPress blog for seo, speed, monetization, traffic, and the minimum required plugins and sites you’ll need to make it happen
- Social media internet marketing goals to have when you’re bored
- List of 14 WordPress plugins your blog should have installed
- How to use javascript to make your GetResponse subscription form check fields
Tags: Author Comment Urls, Blog, Functions.php, Open in New Window, Theme Templates, Wordpress
geez i spent my “life” lookin` for this ha ha..thanks …this is really usefull…
[Reply]
this doesn’t work.
[Reply]
mywebmastertips Reply:
February 18th, 2010 at 7:53 pm
Are you sure? It may not work with every WordPress theme, all you have to do is copy and paste it to the bottom of your functions.php file.
You should check to see if any variables in the code aren’t already being used in your template.
[Reply]
I believe it’s placed correctly…this is the code in my functions.php
<?php
if ( function_exists('register_sidebar') )
register_sidebars(2);
// 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’);
?>
[Reply]
mywebmastertips Reply:
February 18th, 2010 at 11:50 pm
The last part of it should not be $return = “$author”;
it should be this:
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 helps.
[Reply]
I copied and pasted it exactly…not sure why it would be any different…but your code in the main body of the post is what is there
here’s a screen shot:
http://defunkd.com/permanent/screenshot.jpg
[Reply]
[...] 在虎头鱼那看到了通过修改wordpress文件的方法做到评论者主页链接新窗口打开,我嫌麻烦,于是放狗搜索了下,找到了个方法。 [...]
[...] 最后,Dianso同学提供了一个不错的方法,将相应的代码代码复制到function.php文件内(不过建议有相应基础的同学修改),参考地址:请直接点击 ,下个主题考虑用上^^。 « 上一篇:Wordpress下实现图片自动缩放 [...]