You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在WordPress中为单个页面禁用插件?条款页禁用Age Verifier插件

嘿,我来帮你搞定这两个WordPress插件禁用的问题,都是实际开发中常用的方案,分情况给你说清楚:

一、为单个WordPress页面禁用插件

方法1:用现成插件(简单快捷)

  • 推荐用Plugin Organizer这类工具,它能让你在页面/文章的编辑界面直观设置禁用哪些插件,完全不需要写代码,新手友好。安装后找到页面编辑区的「插件控制」选项,勾选要禁用的插件即可生效。

方法2:手动添加代码(无需额外插件)

如果你不想新增插件,可以把下面的代码添加到主题的functions.php文件里(记得先备份主题文件,避免出错!):

function disable_plugins_on_target_page() {
    // 替换成你要禁用插件的页面ID、slug或标题,比如is_page(123)、is_page('privacy-policy')
    if (is_page('terms-and-conditions')) {
        // 列出要禁用的插件主文件路径(从wp-content/plugins/后开始写)
        $plugins_to_disable = array(
            'age-verifier/age-verifier.php',
            'other-plugin/other-plugin.php' // 可添加多个插件
        );
        
        // 获取当前激活插件列表并移除目标插件
        $active_plugins = get_option('active_plugins');
        foreach ($plugins_to_disable as $plugin) {
            $key = array_search($plugin, $active_plugins);
            if ($key !== false) {
                unset($active_plugins[$key]);
            }
        }
        
        // 临时覆盖激活插件列表
        add_filter('pre_option_active_plugins', function() use ($active_plugins) {
            return $active_plugins;
        });
    }
}
add_action('wp_loaded', 'disable_plugins_on_target_page');
二、专门在条款和条件页面禁用Age Verifier插件的函数实现

上面的代码已经包含了针对单个页面禁用特定插件的逻辑,这里给你一个更精准的专属版本:

function disable_age_verifier_on_terms() {
    // 匹配条款和条件页面,可根据实际情况改参数(ID/slug/标题)
    if (is_page('terms-and-conditions')) {
        $age_verifier_path = 'age-verifier/age-verifier.php';
        
        // 用过滤器临时移除该插件的激活状态
        add_filter('pre_option_active_plugins', function($active_plugins) use ($age_verifier_path) {
            if (is_array($active_plugins)) {
                $key = array_search($age_verifier_path, $active_plugins);
                if ($key !== false) {
                    unset($active_plugins[$key]);
                }
            }
            return $active_plugins;
        });
    }
}
// 确保在插件加载前触发,设置优先级为1
add_action('plugins_loaded', 'disable_age_verifier_on_terms', 1);

补充小技巧:

如果上面的方法没生效,可能是插件用了自定义钩子加载内容。你可以查看Age Verifier的源代码,找到它渲染弹窗的钩子和函数,然后用remove_action直接移除:

function remove_age_verifier_popup() {
    if (is_page('terms-and-conditions')) {
        // 替换成插件实际使用的钩子和函数名(比如插件里用wp_footer加载弹窗)
        remove_action('wp_footer', 'age_verifier_render_popup');
    }
}
add_action('wp_loaded', 'remove_age_verifier_popup');

内容的提问来源于stack exchange,提问作者Maroš Minčák

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:23:50