updated   : May 15, 2012
we now have 588 snippets
By : , on March 31, 2011 9:00 am

Replace keywords or cursing in the comments

wordpress snippet

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.

snippet :  PHPcopy
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;
}
  • http://www.facebook.com/profile.php?id=100002506242703 Iago Melanias

    Make a tutorial teaching on the side to replace words.

    • http://wpsnipp.com Kevin Chard

      Hi Iago,
      Thanks for the feedback at this point the site is primarily for snippets that I find online or create for projects I’m working on. However Ill look at adding some tutorials in the future. Hope you like the snippets!

  • http://cudjex.com/ cudjex

    function cudjex($text){$text = str_replace(‘sex’, ‘***’, $text);
    $text = str_replace(‘porno’, ‘***’, $text);
    $text = str_replace(‘cam?? ölüsü seni’, ‘***’, $text);
    $text = str_replace(‘aq’, ‘***’, $text);
    $text = str_replace(‘amk’, ‘***’, $text);
     
    return $text;
    }
    add_filter(‘comment_text’, ‘cudjex’);the simple and useful :)

    • http://wpsnipp.com Kevin Chard

      no problem glad that I could help