从活动监视器插件中删除样式表

时间:2017-06-22 作者:tylorreimer

我正在尝试禁用正在加载的样式Campaign Monitor Wordpress插件,我可以自己设计。

插件中似乎负责加载样式表的代码是:

public static function loadPublicScripts()
 {
    $plugins_url = plugins_url(\'forms-for-campaign-monitor\');

    wp_enqueue_script(Helper::tokenize(\'ajax-script-public\'), $plugins_url . \'/forms/views/public/js/app.js\', array(), false,true);
    wp_register_style(Helper::tokenize(\'custom_cm_monitor_css\'), $plugins_url . \'/forms/views/public/css/app.css\', false, \'1.0.0\');
    wp_enqueue_style(Helper::tokenize(\'custom_cm_monitor_css\') );

    // in JavaScript, object properties are accessed as ajax_object.ajax_url, ajax_object.we_value
    wp_localize_script(Helper::tokenize(\'ajax-script-public\'), \'ajax_request\', array(
        \'ajax_url\' => admin_url(\'admin-ajax.php\')
    ));
}
我假设wp_deregister_style(\'custom_cm_monitor_css\');wp_dequeue_style(\'custom_cm_monitor_css\'); 可以解决这个问题,但似乎不起作用。

是否有人对删除样式有任何见解?

1 个回复
最合适的回答,由SO网友:Dave Romsey 整理而成

句柄的字符串为custom_cm_monitor_css 但它被传递给Helper::tokenize() 它变成了forms-for-campaign-monitor-custom_cm_monitor_css. 请注意,页面源中样式表的ID显示forms-for-campaign-monitor-custom_cm_monitor_css-css 但是结局-css 由WordPress追加。

因此,我们需要使用句柄将样式出列:

forms-for-campaign-monitor-custom_cm_monitor_css
这需要在排队之前发生。不清楚什么时候loadPublicScripts 被最初的问题吸引住了,所以我们会很晚再做。之后,我们将自己的风格排成一列。

add_action( \'wp_enqueue_scripts\', \'wpse_campaign_monitor_styles\', 9999 );
function wpse_campaign_monitor_styles() {
    // Dequeue Campaign Monitor styles.
    wp_dequeue_style( \'forms-for-campaign-monitor-custom_cm_monitor_css\' );

    // Deregister Campaign Monitor styles. (Dequeing should be enough to stop it from being loaded though.)
    wp_deregister_style( \'forms-for-campaign-monitor-custom_cm_monitor_css\' )

    // Enqueue custom Campaign Monitor styles located in:
    // {theme-or-child-theme-name}/css/wpse-campaign-monitor.css
    wp_enqueue_style(
       \'wpse_campaign_monitor_styles\',
        get_stylesheet_directory_uri() . \'/css/wpse-campaign-monitor.css\'
    );
}
此代码尚未测试

结束

相关推荐

在Functions.php中正确地将首页的CSS-TEMPLATE_REDIRECT排队?

我想加载一些特定的css来更改WP首页/主页的主体元素的颜色。在我的主题函数文件中,以下代码似乎有效,但有人能告诉我它是否“正确”吗?//Adding and Encuing styles for Front Page add_action( \'template_redirect\', \'front_page_design\' ); function front_page_design(){ if ( is_front_page() || is_home())