function to erase swear words

Basic Filtering

This is just a simple example and would work if you’re just using it for editors that might slip up here or there and put in a swear word by accident. However, if you have to worry about people trying to “spoof” their words for example “focker, fuker, etc” then you’ll probably need something more complex.

// Basic Implementation
function replace_words($content) {
    // $content = preg_replace("/hate/", "love", $content);
    $content = str_replace('hate', 'love', $content);
    $content = str_replace('foo', 'bar', $content);
    $content = str_replace('bad', 'good', $content);
return $content;
}

// Filter options
add_filter('the_content','replace_words', 2);
add_filter('the_excerpt','replace_words', 2);
add_filter('widget_text','replace_words', 2);
//add_filter('get_comment_text','replace_words', 11);
//add_filter('get_comment_excerpt','replace_words', 11);

Or if you have a bunch of words, you can do this in an array:

function replace_words($text){
        $replace = array(
                // 'BAD WORD' => 'GOOD WORD'
                'crap' => 'poop',
                'boob' => 'breast',
                'ugly' => 'pretty'
        );
        $text = str_replace(array_keys($replace), $replace, $text);
        return $text;
}

Also, just watch out if using the example above because you might run into a situation where you filter out something you didn’t mean to… Think “hell” which could have actually been the word “hello”.

PHPMYADMIN MYSQL

This allows you to replace words in mysql but isn’t a great solution if this is something you need constantly…

UPDATE wp_posts SET post_content = REPLACE (
post_content,
'hate',
'love');

Plugins

There’s tons of plugins to do this, just try some of them out…

WP Content Filter

Word Filter Plus

Web Purify

Text Obfuscator

Profanity Blocker

Replace Default Words

Bleep Filter

Thats just to name a few too. Your best bet in these situations is to just do a search for something like “profanity”, “replace text”, or “content filter” in the wordpress plugins directory….

Example Search:

https://wordpress.org/plugins/search.php?type=term&q=replace+text