2017-10-11 90 views
0

我在wordpress中创建了一个名为bigpont的父主题的子主题。我也在网站上使用woocommerce。我已经征服了我的孩子主题样式表,并且注意到它加载了两次,我不知道为什么。我也想知道如何让它加载,以覆盖woocommerce样式表。这是我目前使用在我functions.php文件中的代码:enqueing stylesheet for a child theme in wordpress

function my_theme_enqueue_styles() { 

$parent_style = 'bigpoint-css'; 

wp_enqueue_style($parent_style, get_template_directory_uri() . '/base.css'); 
wp_enqueue_style('child-style', 
    get_stylesheet_directory_uri() . '/style.css', 
    array($parent_style), 
    wp_get_theme()->get('Version') 
); 
} 
add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles'); 

,这里是样式表是如何被装在我的网站 enter image description here 似乎加载为“Bigpoint的默认-CSS”然后再次添加“child-style-css”

****更新:我发现我的css被加载两次,在我的父主题的functions.php文件中被调用的答案为:

wp_register_style('bigpoint-default', get_stylesheet_uri(), '1.0'); 

所以我用了thi s到撤消:

function unhook_parent_style() { 

    wp_dequeue_style('bigpoint-default'); 
    wp_deregister_style('bigpoint-default'); 

    } 
    add_action('wp_enqueue_scripts', 'unhook_parent_style', 20); 

回答

1

从查看文件class-wc-frontend-scripts.php看起来,如果你以较低的排队脚本像WooCommerce它排入脚本/样式的10

public static function init() { 
     add_action('wp_enqueue_scripts', array(__CLASS__, 'load_scripts')); 
     add_action('wp_print_scripts', array(__CLASS__, 'localize_printed_scripts'), 5); 
     add_action('wp_print_footer_scripts', array(__CLASS__, 'localize_printed_scripts'), 5); 
    } 

所以默认的优先级优先级,它将在WooCommerce样式之后加载并覆盖该样式表,因为该文件将在WooCommerce压缩HTML文档之后加载。

add_action('wp_enqueue_scripts', 'my_theme_enqueue_styles', 100); 

我需要更多的信息来调试重复的样式表发生了什么。

+0

谢谢Andrew帮我在woocommerce css之后加载我的样式表。我发现这在父主题functions.php文件,我相信这是我的CSS文件的其他加载发生的地方:wp_register_style('bigpoint-default',get_stylesheet_uri(),'1.0');但我不知道如何在我自己的functions.php文件中处理这个问题。 –

+0

如果我看不到所有的代码,我都无法回答这个问题。 –

+0

我想通了,并张贴在我的问题,感谢帮助一个WordPress新手:) –