I am starting to doubt my sanity. I read ALL the StackOverflow posts about wp_dequeue_style, but none of the answer were solving my problem. This is my situation:
I have a parent theme and a child theme. The parent theme adds this to the DOM:
<link property="stylesheet" rel='stylesheet'
id='vc_google_fonts_playfair_displayregularitalic700700italic900900italic-css'
href='//fonts.googleapis.com/css?family=Playfair+Display%3Aregular%2Citalic%2C700%2C700italic%2C900%2C900italic&ver=5.9.4'
type='text/css' media='all' />
So the handle is: 'vc_google_fonts_playfair_displayregularitalic700700italic900900italic'.
In the PARENT theme, it is enqueued like this in cms_cta.php:
wp_enqueue_style(
'vc_google_fonts_' . vc_build_safe_css_class( $text_font_data['values']['font_family'] ),
'//fonts.googleapis.com/css?family=' . $text_font_data['values']['font_family'] . $subsets
);
This action is added in the parent theme`s functions.php here:
function kl_vc_elements(){
require_once( get_template_directory() . '/inc/elements/cta/cms_cta.php' );
}
add_action('vc_before_init', 'kl_vc_elements');
In my CHILD theme’s functions.php, I dequeue like this:
function remove_google_fonts()
{
wp_dequeue_style( 'vc_google_fonts_playfair_displayregularitalic700700italic900900italic' );
wp_deregister_style( 'vc_google_fonts_playfair_displayregularitalic700700italic900900italic' );
}
$prio = 10000;
add_action('vc_after_init', 'remove_google_fonts', $prio );
add_action('vc_before_init', 'remove_google_fonts', $prio );
add_action('wp_enqueue_scripts', 'remove_google_fonts', $prio );
- I added other hooks, too, just to rule them out.
- I tried other priority values, such as 1 and
PHP_INT_MAX. - I checked, that the enqueued style is not a dependency of another wp_enqueue_style.
- I checked if it is added via another hook.
- I removed the
wp_enqueue_stylecode to make surecms_cta.phpis really the script that adds the font style (removing the code removes the font). - I checked if it is registered anywhere in the parent theme, but there is only
wp_enqueue_style('vc_googe_fonts_***'), nowp_register_script('vc_googe_fonts_***'). - I checked if
remove_google_fonts()is called (with a good old die;).
Whatever I tried, I can’t get the damned style removed.
Does anybody have an idea, what I oversaw? I’ve spent a whole day debugging but I am out of ideas.
PS: Modifying the parent theme code is not an option!