Dequeing Parent Fontawesome Deques Parent Styles
-
21-04-2021 - |
سؤال
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);
المحلول
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.