I am creating a shortcode plugin for Bootstrap framework that will go along with my theme. However since this would be released to the plugin, if a users’s theme already has Bootstrap.css included, is there a way for me to check this from a plugin?
2 comments
Comments are closed.
You might be able to use
wp_style_is()
to do this:This comes with all the same caveats as @Milo’s solution — it’ll only work if the copy of bootstrap.css was registered or enqueued with a handle of
bootstrap
.References
wp_style_is()
wp_enqueue_style()
There’s no bulletproof way of doing this, as a theme developer could add the
bootstrap.css
file directly to a theme file, or enqueue it under any number of handles, or rename the css file to something else.You could check the
$wp_styles
global forbootstrap
in a handle or filename, but this may fail (as noted above) or give you a false positive ifbootstrap
happens to be in a handle or file unrelated to your bootstrap. It’s also possible to build custom versions of bootstrap, so even if you did locate it, it may not contain all of the styles it’s assumed to contain.Here’s a quick example of peeking into the enqueued styles:
Probably the best option, in my opinion, is to do some cursory checking and inform the user that you may have detected bootstrap in their theme, enqueue the file by default, and provide an option to disable the stylesheet.