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);
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
    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. 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
    Nov 19, 2020 at 12:47

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.