【发布时间】:2021-11-19 02:33:58
【问题描述】:
我正在使用 WordPress,并安装了 Woocommerce 插件。
我在我的主题中添加了模板文件夹并开始自定义我的主题。
现在,我必须从我的主题中删除Woocommerce.css,我在官方网站上找到了代码here
我在function.php中添加了相同的代码
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
或
add_filter( 'woocommerce_enqueue_styles', '__return_false' );
但两个答案都不起作用。我已经安装了 5.7.1 Woocommerce。
我该如何解决这个问题?
function.php
function customtheme_scripts() {
wp_enqueue_style( 'customtheme-style', get_stylesheet_uri(), array(), time() );
wp_style_add_data( 'customtheme-style', 'rtl', 'replace' );
wp_enqueue_script( 'customtheme-navigation', get_template_directory_uri() . '/js/navigation.js', array(), _S_VERSION, true );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
wp_dequeue_style( 'customtheme-woocommerce-style' );
}
add_action( 'wp_enqueue_scripts', 'customtheme_scripts' );
查看源代码
域名只是一个例子。
【问题讨论】:
-
对我来说 add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );在 5.7.1 版上完美运行。确保你清除所有缓存。
-
@MartinMirchev,是的,我试过了,但它不起作用。我有自己的自定义主题,我在 function.php 文件中添加了上面的代码。
-
我已经在店面和自定义主题上进行了测试。两者都可以正常工作。
-
@MartinMirchev,刚刚更新了我在问题中的代码。请检查一次好吗?
-
很高兴为您提供帮助!快乐编码! :)
标签: php css wordpress woocommerce hook-woocommerce