April 30, 2008

WordPress Coding

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 :)


Share this via: Twitter | Facebook | Y! Buzz | Stumble | Digg | Delicious | Others


{ 23 comments… read them below or add one }

1 Nik June 29, 2010 at 5:36 pm

Nope, it doesn’t work, since WP3.0. Any ideas?

Reply

2 Mohan June 29, 2010 at 6:57 pm

How come? I have changed it on WP 3.0 on this blog and it is working!!! you can test it out yourself :)

Reply

3 Vishal May 13, 2010 at 9:23 am

Thanks a lot for this info Mohan…was looking to change it for a while now…will do it right away :)

Reply

4 Mohan May 13, 2010 at 9:28 am

Awesome! Glad it was useful for you :)

Reply

5 AnandK May 13, 2010 at 8:03 am

Nice – I will try it out; I was looking for a way to do it ! :)

Reply

6 Mohan May 13, 2010 at 8:59 am

Great! all the best :)

Reply

7 dave joneja May 13, 2010 at 6:48 am

Useful information.
I am so inspired by Randy Pausch’s video. Thank you!

Reply

8 Mohan May 13, 2010 at 8:59 am

Glad you liked it!

Reply

9 zachary December 17, 2009 at 10:56 pm

doesn’t this get over-written when you upgrade WP?

Reply

10 Mohan December 18, 2009 at 5:32 am

Hi Zachary, you are right. the above mentioned method will be overwritten whenever WP is upgraded.

Reply

11 Ricci September 12, 2009 at 6:51 pm

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

Reply

12 Mohan September 12, 2009 at 10:50 pm

Hi Ricci, I am glad that my post was helpful to you.

Reply

13 Alexwebmaster March 3, 2009 at 3:13 pm

Hello webmaster
I would like to share with you a link to your site

Reply

14 Melinda February 14, 2009 at 10:02 pm

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.

Reply

15 boomzefenue February 11, 2009 at 9:09 am

fascinating and educational, but would participate in something more on this topic?

Reply

16 Mohan December 25, 2008 at 6:57 am

@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.

Reply

17 JK December 25, 2008 at 5:04 am

Mohan, Thanks for your post. I saw a few plugins to do this but your solution is far more simple. Great job!

Reply

18 Mohan December 8, 2008 at 11:11 am

@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.

Reply

19 Shirley December 7, 2008 at 8:13 pm

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.

Reply

20 Mohan November 12, 2008 at 12:03 pm

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!

Reply

21 RAG November 12, 2008 at 11:42 am

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.

Reply

22 Mohan November 12, 2008 at 10:31 am

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.

Reply

23 Danny November 12, 2008 at 1:55 am

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

Reply

Leave a Comment

{ 1 trackback }

Previous post:

Next post: