I AM LISTENING TO
|

WHAT I LIKE

Concurrent connections – Server – Cloud & RAM WordPress as a development platform & the JSON evolution
Development     WordPress    

Remove WordPress CSS / JS / Fonts website clutter



22. May 2015


WordPress is fun, but many of my clients take the plugin fun to new levels 🙂

Depending on how well plugins / shortcodes have been integrated, linked JavaScript & CSS files can clutter up your pages really fast.

The problem is that many plugins do not load external files on demand. Same applies for WebFonts that have been added to the system.

THE HUNT

Its no fun hunting down all those resources and slim down pages manually, but sometimes there is no way around it.

In WordPress CSS & JavaScript files are enqueued by plugins / themes.

THE QUEUE

CSSJavaScript

CLEANUP

To remove files from pages you need to unregister (CSS / JavaScript) those files using their specific handle. This also allows you to replace a specific file with your own version.

DO YOU HAVE A NAME?

The big problem is finding the names of the enqueued files, their handles. They are often hidden deep in the plugins. But if they are registered somewhere, you should be able to find them somewhere 🙂

Add this to your functions.php and you will get a nice overview of all the styles and their handles registered. You can do the same for the registered scripts.

This will get you an overview of all the registered files. Now its only a matter of doing the unregister operation with some simple WordPress conditional  logic.

IS THERE A PLUGIN FOR THAT?

Yes there is and it is called “Asset Queue Manager” …

“This tool allows you to monitor, dequeue and requeue scripts and styles that are enqueued on your site. It is designed for frontend performance engineers who want to view and manage all assets enqueued on any page and control the minification and concatenation themselves.”

BREAKING STUFF

Messing with styles can be ugly, but often wont break things completely. Messing with JavaScript includes can cripple a setup badly. So you should be really sure which scripts / styles can be deactivated on specific pages. Please do not experiment on a live website … I warned you ! 🙂

… enjoy coding




Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz