Home / comment / Replace keywords or cursing in the comments
  • How to Replace keywords or cursing in the comments

    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.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    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;
    }
    

    ( WordPress codex functions, hooks, in this snippet. )

    pre_comment_content, add_filter, wp,
  • Make a tutorial teaching on the side to replace words.

    • 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!

  • 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 :)

  • jignesh

    good topic

  • what happen if this keywords inside an img tag. I tried and it caused a problem. We can’t see images. My suggestion is it must be a filter that word must not inside a “img” and “a” tag. How can we check ?