Deregistering WordPress Stylesheets in 60 Seconds

There are times in which we inherit a WordPress project that's already been in use for some time. This means that we're likely dealing with some form of legacy code, be it at the theme level or the plugin level.

Sometimes, we're able to simply upgrade the dependencies that exist in the project. Other times, we have to leave the core files but need to replace some of them with our own. To make sure our changes aren't overwritten if the customer upgrades their version of, say, the plugin in question, then we may need to deregister a script or a stylesheet in order to register our own that's located elsewhere in the project.

To do that, we can hook into the wp_enqueue_script API function and write some custom code. Here's how to do exactly that:

In the video above, example.min.css or example.css (whichever one exists) is removed from the enqueued WordPress styles.

After doing this, you should be able to hook into the same function and register your own custom styles to help improve the current state of the project.

 

More Details

Learn more about WordPress Development on Envato Tuts+:

What's With the 60 Seconds?

This is part of a new series of quick video tutorials on Tuts+. We're aiming to introduce a range of subjects, all in 60 seconds, just enough to whet your appetite. Let us know in the comments what you thought of this video and what else you'd like to see explained in 60 seconds!

Anything Else?

In the meantime, I hope this proved to be useful in helping improve your development workflow.

For more information about WordPress development, you can see all of my courses and tutorials on my profile page, and you can follow me on my blog and/or Twitter at @tommcfarlin where I talk about software development in WordPress.

Please don't hesitate to leave any questions or comments in the feed below, and I'll aim to respond to each of them as time permits.

Tags:

Comments

Related Articles