![]() ![]() Otherwise, you may end up with unintended consequences or non-functioning code. 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. I am trying to enqueue style or may be scripts depending on page. To be clear, this post is not about Font Awesome. it is causing problem because i did not do it before. 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: Top See also WPDependencies::add () WPDependencies::enqueue () Top Parameters handle string Required Name of the stylesheet. If we find what we’re looking for, then we deregister it. Description Registers the style if source provided (does NOT overwrite) and enqueues.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 |