最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - Avoid loading css from parent theme

programmeradmin2浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 1

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:

  • https://developer.wordpress.org/reference/functions/wp_dequeue_style/
  • https://developer.wordpress.org/reference/functions/wp_deregister_style/
发布评论

评论列表(0)

  1. 暂无评论