1

Does anyone use a function that will just not print swear words? We don't have any, and we edit for them, but in giving more writers more publishing privileges, it could lead to a situation with swear words. I'd rather just not print the words, possibly.

1
2

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

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.