Replace keywords or cursing in the comments

Adding this snippet to the functions.php of your wordpress theme will replace keywords like cursing or even affiliate links within your post comments. May even be fun to change some random words lol, however keep in mind the filtered content will be saved.

 

 

add_filter( 'pre_comment_content', 'wps_filter_comment' );
function wps_filter_comment($comment) {
$replace = array(
// 'WORD TO REPLACE' => 'REPLACE WORD WITH THIS'
'foobar' => '*****',
'hate' => 'love',
'zoom' => '<a href="http://zoom.com">zoom</a>'
);
$comment = str_replace(array_keys($replace), $replace, $comment);
return $comment;
}

Be Sociable, Share!

Leave a comment