我已经为WordPress创建了此内容审查代码(Ezoic需要)

pgky5nke  于 2023-05-06  发布在  WordPress
关注(0)|答案(1)|浏览(123)

我为WordPress创建了这个内容审查代码,这个代码对那些使用Ezoic广告赚钱的博客非常有帮助。Bcz ezoic有一个不良内容选项。
这段代码为我工作,这就是为什么我与你分享这段代码,如果有人想修改这段代码或想增加功能可以这样做:

///Content Censor code

function censor_content($content) {
    // Array of words to censor
    $censored_words = array('word1', 'word2', 'word3');

    // Loop through each word to censor
    foreach ($censored_words as $word) {
        // Create a regular expression pattern to match the word
        $pattern = '/\b' . $word . '\b/i';

        // Replace the word with censored version
        $content = preg_replace_callback($pattern, function($matches) {
            $word = $matches[0];
            $censored_word = substr($word, 0, 2) . str_repeat('*', strlen($word) - 3) . substr($word, -1);
            return $censored_word;
        }, $content);
    }

    // Return the censored content
    return $content;
}

// Add the censor_content function to the WordPress content filter
add_filter('the_content', 'censor_content');
wgmfuz8q

wgmfuz8q1#

将此代码粘贴到functions.php或custome插件文件中

///Content Censor code

function censor_content($content) {
    // Array of words to censor
    $censored_words = array('word1', 'word2', 'word3');

    // Loop through each word to censor
    foreach ($censored_words as $word) {
        // Create a regular expression pattern to match the word
        $pattern = '/\b' . $word . '\b/i';

        // Replace the word with censored version
        $content = preg_replace_callback($pattern, function($matches) {
            $word = $matches[0];
            $censored_word = substr($word, 0, 2) . str_repeat('*', strlen($word) - 3) . substr($word, -1);
            return $censored_word;
        }, $content);
    }

    // Return the censored content
    return $content;
}

// Add the censor_content function to the WordPress content filter
add_filter('the_content', 'censor_content');

相关问题