X

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

Comments  Leave a Reply

  1. Cihan Küsmez July 27, 2013 at 5:24 pm

    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 ?

  2. good topic

  3. 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 🙂

    1. no problem glad that I could help

  4. Make a tutorial teaching on the side to replace words.

    1. 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!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!