禁用woocommerce默认样式stylesheet
用woocommerce建站有时我们不想要它的默认样式,那要如何屏蔽呢?当然ytkah是不会告诉你去注释删除css代码的,默认情况下WooCommerce会嵌入3个样式表,我们可以通过在当前主题的function.php文件中添加以下代码禁用它们,
1 | add_filter( 'woocommerce_enqueue_styles' , '__return_empty_array' ); |
参考资料https://gist.github.com/woogists/8af93b901eac5d4dc2fb1452516c1079#file-wc-disable-default-stylesheet-php
如果您正在构建自定义主题,这是推荐的方法。删除默认的WooCommerce样式表并加入自己的队列将在WooCommerce核心更新期间保护您。
上面是屏蔽所有默认样式,如果你想禁用特定的样式表(如:你不想包含处理样式表),你可以使用以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** * Set WooCommerce image dimensions upon theme activation */ // Remove each style one by one add_filter( 'woocommerce_enqueue_styles' , 'jk_dequeue_styles' ); function jk_dequeue_styles( $enqueue_styles ) { unset( $enqueue_styles [ 'woocommerce-general' ] ); // Remove the gloss unset( $enqueue_styles [ 'woocommerce-layout' ] ); // Remove the layout unset( $enqueue_styles [ 'woocommerce-smallscreen' ] ); // Remove the smallscreen optimisation return $enqueue_styles ; } // Or just remove them all in one line add_filter( 'woocommerce_enqueue_styles' , '__return_false' ); |
参考资料https://gist.github.com/woogists/1f779d37ecfda7fae76ce22b513fa4b6#file-wc-disable-specific-stylesheets-php
然后插入自己定义的样式,如:
1 2 3 4 5 6 7 8 9 10 11 | /** * Enqueue your own stylesheet */ function wp_enqueue_woocommerce_style(){ wp_register_style( 'mytheme-woocommerce' , get_template_directory_uri() . '/css/woocommerce.css' ); if ( class_exists ( 'woocommerce' ) ) { wp_enqueue_style( 'mytheme-woocommerce' ); } } add_action( 'wp_enqueue_scripts' , 'wp_enqueue_woocommerce_style' ); |
参考资料https://gist.github.com/woogists/bdd2a926e000f72bed3217200f203d53#file-wc-default-stylesheet-php

加微信交流
标签:
wordpress
, woocommerce
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
2019-01-16 win10安装pycharm及汉化包
2014-01-16 用sql合并列,两句话合为一句