![]() This also has the benefit that every time you save any file while still developing it, you don’t have to take care of the cache, your browser will always load the latest file. Nowadays I usually use the latest apporach. But then you have to update all these string (for all files) manually and it’s easy to forget one, which will result in the browser loading old files from it’s cache. In the past, I have used the first or third option. A dynamic modification date of the file that’s enqueued.A static modification date of the file that’s enqueued.The next parameter is the location of the style sheet I’m trying to enqueue. This is the unique identifier for the style sheet. '/css/', array (), '', 'all') Let’s break this down a bit: ‘gb-css’ is my handle. wpenqueuestyle ('gb-css', gettemplatedirectoryuri (). A static modification date of the plugin Here is how I call the main style sheet for Gav’s Blog.A static version number matching the version of the plugin If it is not added, and if your custom script depends on it (like you wrote in code) it will be added by wordpress.As your files will probably not (only) change when WordPress gets updated, you should use a different version string. This version number is meant to help you with caching. If you don’t define one yourself, it would append the current version number of WordPress, which today would be 5.9, to the end of the URL. For child themes: get_stylesheet_directory_uri()Īs you can see in the example above, WordPress will add a version number.For themes: get_template_directory_uri().For plugins: plugins_url() or plugin_dir_url().These are the ones, you would usually use: If you enqueue a file in a plugin or theme, there are different functions you can use. This might seem OK for most of you, but as the wp-content folder can have a different name (some security plugins do that – which is usually not a great idea), you should always use helper functions to get the relative path to that folder. In the example above, we use a relative path to the wp-content/plugins folder. While this would work, there are some issues with this simple way.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |