css - 店面子主题仍然加载父 CSS

标签 css wordpress storefront

我对 Storefront 子主题有疑问。 我创建了一个店面子主题,就像他们在这里建议的那样:https://docs.woocommerce.com/document/set-up-and-use-a-child-theme/

子主题工作正常,我可以编写我的 CSS,在 functions.php 中编写我的代码并覆盖模板文件,但子主题仍然加载父主题 CSS。

如何在不加载父主题的情况下创建子主题?

最佳答案

将这些函数添加到您子主题的 functions.php。

此代码将禁用 Storefront 默认 CSS 的加载。

来源:https://github.com/stuartduff/storefront-child-theme

/**
 * Storefront automatically loads the core CSS even if using a child theme as it is more efficient
 * than @importing it in the child theme style.css file.
 *
 * Uncomment the line below if you'd like to disable the Storefront Core CSS.
 *
 * If you don't plan to dequeue the Storefront Core CSS you can remove the subsequent line and as well
 * as the sf_child_theme_dequeue_style() function declaration.
 */

add_action( 'wp_enqueue_scripts', 'sf_child_theme_dequeue_style', 999 );

/**
 * Dequeue the Storefront Parent theme core CSS
 */
function sf_child_theme_dequeue_style() {
    wp_dequeue_style( 'storefront-style' );
    wp_dequeue_style( 'storefront-woocommerce-style' );
}

此外,您可以禁用 WooCommerce 标准样式表,

来源:https://docs.woocommerce.com/document/disable-the-default-stylesheet/

/**
 * 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;
}

关于css - 店面子主题仍然加载父 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53945041/

相关文章:

wordpress - 从Wordpress用户列表中隐藏特定的管理员帐户

html - 使用媒体查询更改页面内容 (WordPress)

vue.js - 如何将 vuestorefront 与 shopify 集成

javascript - 在更大的屏幕尺寸下消失的导航

javascript - 带有选择框的 JQuery

css - 是否有任何我可以遵循的 CSS 填充启发式方法?

html - 将 OBJ 数据转换为 CSS3D

WordPress 改进 REST API - SHORTINIT 不起作用

css - woocommerce 问题使产品页面响应

twig - Shopware 6 meta.html.twig 店面模板无法扩展