
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.

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
Could you briefly explain how this function accomplishes it’s task?
This could be a nice code to have in the future..
But i love the link in the comment it gives opportunity other people to get traffic by dint of other sites.
personally I dnt like this feature….
Is this works ? I tried with WP 271 and doesn’t work for me.
can someone help ?
thanks
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!
I think links within the comments is a nice way to give something back to the people that support your blog.
Trackbacks: