Download the PHP package mindkomm/theme-lib-script-loader-tags without Composer
On this page you can find all versions of the php package mindkomm/theme-lib-script-loader-tags. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mindkomm/theme-lib-script-loader-tags
More information about mindkomm/theme-lib-script-loader-tags
Files in mindkomm/theme-lib-script-loader-tags
Package theme-lib-script-loader-tags
Short Description Async and defer attribute helper tags for enqueueing scripts in WordPress themes
License MIT
Informations about the package theme-lib-script-loader-tags
Script Loader Tags
Helper functionality for enqueueing scripts in WordPress themes with the following <script>
tag attributes, because WordPress doesn’t support that for wp_register_script()
or wp_enqueue_script()
:
async
defer
nomodule
type="module"
WordPress doesn’t provide a default way to enqueue scripts with the above attributes. This package
- Adds a
script_loader_tag
filter to make it possible for you to set async and defer attributes through the name of the script that should be enqueued. - Adds a
update_script_tag()
function so you can control how scripts are loaded, when you don’t have control over the name of the handle the script is using.
Installation
You can install the package with Composer:
Usage
Use name suffixes
Append any of the following suffixes to the name of your script to automatically set the attribute:
|async
for anasync
attribute|defer
for adefer
attribute|nomodule
for anomodule
attribute|module
fortype="module"
attribute
This will produce the following output:
It’s also possible to chain more than one suffix.
Use a function
You can use the update_script_tag()
function to set a filter that adds the attributes.
It‘s also possible to add more than one handle and/or attribute if you pass an array:
This function is useful
- if you want to change the method of an existing script that you didn’t enqueue yourself.
- if you use
wp_register_script()
, where you shouldn’t add suffixes to the script handle.
Support
This is a library that we use at MIND to develop WordPress themes. You’re free to use it, but currently, we don’t provide any support.