In the wordpress 2.5 and above versions, comments author URL opens up in the same window. This could possibly make your blog reader to get away to other sites. If you want it to be opened up in new window, you need to make the following code changes.
Look for this file : ../wp-includes/comment-template.php and take a look at the piece of code which is mentioned as below.
function get_comment_author_link() {
$url = get_comment_author_url();
$author = get_comment_author();
if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "<a href='$url' rel='external nofollow'>$author</a>";
return apply_filters('get_comment_author_link', $return);
}
Modify the above block of code with changes as shown below.
function get_comment_author_link() {
$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 apply_filters('get_comment_author_link', $return);
}
Thats it. You are done! Enjoy the wordpress while retaining traffic on your site :)
{ 23 comments… read them below or add one }
Nope, it doesn’t work, since WP3.0. Any ideas?
How come? I have changed it on WP 3.0 on this blog and it is working!!! you can test it out yourself :)
Thanks a lot for this info Mohan…was looking to change it for a while now…will do it right away :)
Awesome! Glad it was useful for you :)
Nice – I will try it out; I was looking for a way to do it ! :)
Great! all the best :)
Useful information.
I am so inspired by Randy Pausch’s video. Thank you!
Glad you liked it!
doesn’t this get over-written when you upgrade WP?
Hi Zachary, you are right. the above mentioned method will be overwritten whenever WP is upgraded.
THANK YOU! I spent way too much time yesterday looking for this in the template files and even in the includes. How I missed comment-template (duh), I’ll never know. You rock. – Ricci
Hi Ricci, I am glad that my post was helpful to you.
Hello webmaster
I would like to share with you a link to your site
Thank you so much, this has been driving me crazy. I tried some other things that didn’t work. I would much rather do this than install yet another plugin to do something that turned out to be so simple.
fascinating and educational, but would participate in something more on this topic?
@JK
Yeah, plugins do the same job of over riding certain piece of native code. It is always better to get it done through simple solutions like this than having plugins. I am glad that was useful for you.
Mohan, Thanks for your post. I saw a few plugins to do this but your solution is far more simple. Great job!
@Shirley
Thanks for pointing me to a different way of doing it. yes, I agree with you.. Editing on theme’s functions.php is a safer way of accomplishing this task.
You could use a filter in your theme’s functions.php file to accomplish the same thing. It’s a better approach because you don’t have to edit the code and risk making fatal changes. Additionally, if this is part of your theme, it stays with you when you upgrade… Just a thought.
Hi RAG, Why not! Sure, I will write up a post on creating own blogs some time very soon. You gave me a topic to write up my next article.. Cheers!
Hi Mohan,
Can you please write up a post on “How to create own blog”?
I know there are some free blogs available like blogspot, but URL of these are not attractive.
I also comes from IT field but have no idea bout php. But i have liitle knowledge about html.
Hi Danny, I am glad that my post helped someone like you. Feel free to post back for any help you may require wrt WordPress customization.
Simple but brilliant!
Many thanks, Mohan. I know it had to be something as simple as this but I am not a PHP coder and just did not know where to start looking.
Best wishes,
Danny
{ 1 trackback }