Avoid loading css from parent theme

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?

Topic parent-theme child-theme functions Wordpress

Category Web


In 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:

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.