How to: get rid of links in your comments

February 11, 2009 at 10:45 am

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!