最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

css - Dequeing Parent Fontawesome Deques Parent Styles

programmeradmin3浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

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);

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.

发布评论

评论列表(0)

  1. 暂无评论