admin管理员组文章数量:1314292
I'm trying to dequeue fontawesome from a parent theme in my child theme. For this I use the following code:
function si_dequeue_child_styles()
{
wp_dequeue_style('wp-bootstrap-starter-fontawesome-cdn');
wp_deregister_style('wp-bootstrap-starter-fontawesome-cdn');
}
add_action('wp_print_styles', 'si_dequeue_child_styles', 99);
However, this seems to also dequeue the parents theme styles, which I don't want. What could be causing this?
For reference, I'm using the widely know WP Bootstrap Starter theme.
Solution
I found the cause for my problem. I used the "Child Theme Configurator" plugin to generate my child theme. The plugin put the following code at the top of my functions.php. The plugin decided that wp-bootstrap-starter-fontawesome-cdn
was relevant for the loading of the themes main CSS (look at the very end of the wp_enqueue_style
function):
if (!function_exists('chld_thm_cfg_parent_css')):
function chld_thm_cfg_parent_css()
{
wp_enqueue_style('chld_thm_cfg_parent', trailingslashit(get_template_directory_uri()) . 'style.css', array('wp-bootstrap-starter-bootstrap-css', 'wp-bootstrap-starter-fontawesome-cdn'));
}
endif;
add_action('wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10);
I'm trying to dequeue fontawesome from a parent theme in my child theme. For this I use the following code:
function si_dequeue_child_styles()
{
wp_dequeue_style('wp-bootstrap-starter-fontawesome-cdn');
wp_deregister_style('wp-bootstrap-starter-fontawesome-cdn');
}
add_action('wp_print_styles', 'si_dequeue_child_styles', 99);
However, this seems to also dequeue the parents theme styles, which I don't want. What could be causing this?
For reference, I'm using the widely know WP Bootstrap Starter theme.
Solution
I found the cause for my problem. I used the "Child Theme Configurator" plugin to generate my child theme. The plugin put the following code at the top of my functions.php. The plugin decided that wp-bootstrap-starter-fontawesome-cdn
was relevant for the loading of the themes main CSS (look at the very end of the wp_enqueue_style
function):
if (!function_exists('chld_thm_cfg_parent_css')):
function chld_thm_cfg_parent_css()
{
wp_enqueue_style('chld_thm_cfg_parent', trailingslashit(get_template_directory_uri()) . 'style.css', array('wp-bootstrap-starter-bootstrap-css', 'wp-bootstrap-starter-fontawesome-cdn'));
}
endif;
add_action('wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10);
Share
Improve this question
edited Nov 19, 2020 at 11:58
TheKidsWantDjent
asked Nov 19, 2020 at 11:47
TheKidsWantDjentTheKidsWantDjent
3154 silver badges20 bronze badges
3
- Did you check if their styles require this as a dependency? If so, it cannot be loaded now and hence the result. To avoid this, you can dequeue the parent theme and enqueue it on your own - now without the dependency. – kero Commented Nov 19, 2020 at 11:48
- I found the problem. It was a dependency, as you said, but it wasn't in the parent theme, it was in the child theme (the one place where I didn't look). I'll update my post. – TheKidsWantDjent Commented Nov 19, 2020 at 11:55
- If possible, please consider writing this as an actual answer (might take 2d, I'm not so sure right now) and then mark it as accepted – kero Commented Nov 19, 2020 at 12:47
1 Answer
Reset to default 0Solution
I found the cause for my problem. I used the "Child Theme Configurator" plugin to generate my child theme. The plugin put the following code at the top of my functions.php. The plugin decided that wp-bootstrap-starter-fontawesome-cdn
was relevant for the loading of the themes main CSS (look at the very end of the wp_enqueue_style
function):
if (!function_exists('chld_thm_cfg_parent_css')):
function chld_thm_cfg_parent_css()
{
wp_enqueue_style('chld_thm_cfg_parent', trailingslashit(get_template_directory_uri()) . 'style.css', array('wp-bootstrap-starter-bootstrap-css', 'wp-bootstrap-starter-fontawesome-cdn'));
}
endif;
add_action('wp_enqueue_scripts', 'chld_thm_cfg_parent_css', 10);
In any case, it makes sense to search the entire project for any occurrence of the style being enqueued, even where you don't expect it and look for dependencies.
本文标签: cssDequeing Parent Fontawesome Deques Parent Styles
版权声明:本文标题:css - Dequeing Parent Fontawesome Deques Parent Styles 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741964686a2407477.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论