In a parent theme (Foodica Pro) functions.php I have function foodica_scripts(), where css and js are loaded in page header, including:
wp_enqueue_style( 'media-queries', get_template_directory_uri() . '/css/media-queries.css', array(), WPZOOM::$themeVersion );
This media-queries.css will take a lot of work to overwrite (using different breakpoints). I want to avoid loading this css file, but without touching parent theme. Is there any way to do it in child theme only?
In a parent theme (Foodica Pro) functions.php I have function foodica_scripts(), where css and js are loaded in page header, including:
wp_enqueue_style( 'media-queries', get_template_directory_uri() . '/css/media-queries.css', array(), WPZOOM::$themeVersion );
This media-queries.css will take a lot of work to overwrite (using different breakpoints). I want to avoid loading this css file, but without touching parent theme. Is there any way to do it in child theme only?
Share Improve this question edited Mar 15, 2022 at 8:23 Filip Witkowski asked Jan 11, 2020 at 16:08 Filip WitkowskiFilip Witkowski 1135 bronze badges1 Answer
Reset to default 1In your child theme (which I am assuming you are using) functions.php
file:
function wpse_356175_assets() {
wp_dequeue_style( 'media-queries' );
}
add_action( 'wp_enqueue_scripts', 'wpse_356175_assets' );
Utilise wp_dequeue_style
and or wp_deregister_style
depending on how the stylesheet was registered/enqueued.
If necessary adjust the priority of your action to fire after the registered/enqueued file from the parent theme, e.g:
add_action( 'wp_enqueue_scripts', 'wpse_356175_assets', 100 );
Useful documentation:
- https://developer.wordpress.org/reference/functions/wp_dequeue_style/
- https://developer.wordpress.org/reference/functions/wp_deregister_style/