When I enqueue Bootstrap with wp_enqueue_style()
, Bootstrap is loaded after the child theme’s style.css
and will override style.css
.
One way to load style.css
after Bootstrap is to enqueue style.css
as well, but this will cause it to be loaded twice.
Any idea how to enqueue style.css
once AND after Bootstrap?
Thanks!
2 Answers
Mostly the parent theme might be enqueing the child theme’s style.css
, if so you can dequeue it by using handle and then enqueue with proper dependency.
If the child theme’s handle is child-theme-style
, then dequeue it using
wp_dequeue_style('child-theme-style')
then enqueue it as needed like so.
wp_enqueue_style('child-theme-dep',get_stylesheet_uri(),array('bootstrap-handle-here'))
We can easily know the child theme stylesheet url by looking at the link output in the head, for example in the attached image.
<link rel="stylesheet" id='hybrid-style-css' href="https://wptavern.com/wp-content/themes/stargazer-child-dev/style.css?ver=4.6.1" type="text/css" media="all" />
Tells us that the child theme’s enqueue handle is hybrid-style
which is the id
without -css
.