![]() ![]() Simply put, instead of having all your code in one place, which would slow down your load time, you use the enqueue function. Otherwise, you may end up with unintended consequences or non-functioning code. using the wpenqueuescript and wpenqueuestyle functions, you inform WordPress when and where to load custom scripts and stylesheets. Remember to be careful when doing this: Make sure that you’ve properly prioritized your hooks. That just happened to be the example used. Instead, it’s about how to remove existing, registered style. ![]() To be clear, this post is not about Font Awesome. Be sure to check it out if you’ve not used it before.įinally, remember that when you’re ready to enqueue your own asset, the priority for the call needs to be after the one for deregistering the previous version of the asset. It’s a simple function, but really useful in situations like this. Pluck a certain field out of each object in a list Note that the above code takes advantage of wp_list_pluck which is a useful function when dealing with lists. Then we need define the function to look for a copy of the stylesheet so that we can unregister it: If we find what we’re looking for, then we deregister it.Register a custom function with `wp_enqueue_scripts`.As such, we have to make sure that we properly prioritize the hook. ![]() One of the challenges that comes with doing this in the context of a plugin is that you don’t know when the other styles are enqueued. Furthermore, the version of Font Awesome maybe be the minified version or not so we need to check for that. The requirements call for some updated icons that aren’t available in the existing version. The existing site uses something like Font Awesome, but it’s using an older version. This, in and of itself, is not that difficult, but if it’s using an older version of a dependency, then it can get a little more complicated.įor example, let’s say that you’re building a plugin for an existing site. When working on a pre-existing version of a site, you may need to check if a style is already loaded. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |