Post Pic

How to: get rid of links in your comments

As WpRecipes became one of the most popular WordPress related blogs, I had to face the problem of people inserting links in comments. Some links are relevant, but some aren’t at all. here is a solution to say goodbye to links in comments.

Just paste this code in your function.php file. Once the file is saved, you can say goodbye to links and other undesired html in your comments.

function plc_comment_post( $incoming_comment ) {
	$incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
	$incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );
	return( $incoming_comment );
}

function plc_comment_display( $comment_to_display ) {
	$comment_to_display = str_replace( ''', "'", $comment_to_display );
	return $comment_to_display;
}

add_filter( 'preprocess_comment', 'plc_comment_post', '', 1);
add_filter( 'comment_text', 'plc_comment_display', '', 1);
add_filter( 'comment_text_rss', 'plc_comment_display', '', 1);
add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);

Thanks to Peter's useful crap for this awesome recipe!

17 Responses

Feb 11 2009 15:11

Could you briefly explain how this function accomplishes it’s task?

Feb 12 2009 03:31

This could be a nice code to have in the future..

Feb 19 2009 09:25

But i love the link in the comment it gives opportunity other people to get traffic by dint of other sites.

Mar 13 2009 18:05

personally I dnt like this feature….

Mar 29 2009 13:28

Is this works ? I tried with WP 271 and doesn’t work for me.

can someone help ?

thanks

May 20 2009 14:25

I don’t get the point why to disable links within the comments. There are a lot of comments misused by spammers and other so called “seo’s”. But you can still administer your comments. I want to give the community a tribute and that’s why, besides my articles, I installed CommentLuv!

Oct 07 2009 22:49

I think links within the comments is a nice way to give something back to the people that support your blog.

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required