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

Dequeue CSS of the Parent Theme

programmeradmin3浏览0评论

New to WordPress. I have been working on my own child theme. Everything is working so far but I have a question on dequeuing a parent theme's CSS.

Right now, the parent theme enqueues a AOS.css file which adds "action of scroll". I am not a big fan of this effect and want to dequeue this style entirely in my child theme. My question is if I dequeue but the parent theme still includes AOS related stuff would that crash the site or I can safely remove AOS.css?

New to WordPress. I have been working on my own child theme. Everything is working so far but I have a question on dequeuing a parent theme's CSS.

Right now, the parent theme enqueues a AOS.css file which adds "action of scroll". I am not a big fan of this effect and want to dequeue this style entirely in my child theme. My question is if I dequeue but the parent theme still includes AOS related stuff would that crash the site or I can safely remove AOS.css?

Share Improve this question edited May 4, 2020 at 6:06 Brooke. 3,9121 gold badge27 silver badges34 bronze badges asked May 3, 2020 at 22:02 ExcitedtoworkExcitedtowork 1 1
  • 1 You should be good to dequeue it, but you may then need to address certain styling deficiencies by writing them into your child style.css. – Tony Djukic Commented May 3, 2020 at 22:21
Add a comment  | 

2 Answers 2

Reset to default 0

Tony has it right, you can dequeue the style without the site having an error. That is because of the way CSS works. If the DOM can't find a specific CSS class/ID that is in the HTML it is simply ignored. Tony is also right, that you may need to add some styles back in if they were included in the, now removed, CSS file.

If you were removing a JavaScript file on the other hand you would need to be more careful to make sure that one of the removed functions wasn't going to cause a conflict elsewhere. A quality theme developer will take that into consideration and often wrap functions to make sure all functions are there, but that's not always the case.

Try this code in the currently existing theme for the dequeue style.

add_action( 'wp_enqueue_scripts', 'mywptheme_child_deregister_styles', 11 );
function mywptheme_child_deregister_styles() {
    wp_dequeue_style( 'mywptheme' );
}

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论