How can I get all enqueued styles or scripts and then deregister them all at once?
Leave a Reply
You must be logged in to post a comment.
How can I get all enqueued styles or scripts and then deregister them all at once?
You must be logged in to post a comment.
I hope you know what you are doing. You can use the
wp_print_styles
andwp_print_scripts
action hooks and then get the global$wp_styles
and$wp_scripts
object variables in their respective hooks.The “registered” attribute lists registered scripts and the “queue” attribute lists enqueued scripts on both of the above objects.
An example code to empty the scripts and style queue.
You can also do it on a per basis by finding the handlers being called upon, search for
wp_enqueue_style
orwp_enqueue_script
you can deregister them like this on yourfunctions.php
Hameedullah solution is better, however if you run into problems due to some scripts not loading give the above a shot.
Hello you can also remove all these script, and wordpress will work correctly.
Since WordPress lets you remove all the script, and the ones he needs can not be removed.
The audio script and others are script extras, so this will not cause problems in your wordpress.
Hameedullah’s method is useful, however if you only want this to work in the front end of the site (eg:not your WordPress dashboard) you need to add a conditional to force it to bail early.
I’m using a check mentioned in this question along with
is_admin()
to do this.