![]() Also, newer versions of php have type checking, so you should probably add your parameter and return types into your function call. Also, instead of manipulating the tag string, a better way to go about this would be to load it into a DOMDocument object, manipulate that, and convert it back to a string afterward. Within the action hook, you can use several functions and embed them in the functions.php file: wpregisterscript() wpenqueuescript() wpregisterstyle() wpenqueue. Let’s go through the basics of the wpenqueuescript hook that you’ll use to load your assets. because jQuery should probably be loaded in the head before anything else. We now know what enqueueing is and how it works. Also, for the non-admin pages, you want to exclude jQuery. How to add defer or async attribute to wpaddinlinescript wpenqueuescript ( 'script', pluginsurl ( '/test/js/script. Filters the HTML script tag of an enqueued script. For general cases not pertaining to this contact-form-7 plugin, where you are adding the defer tag to all scripts, you probably want to exclude it from the admin pages, because those rely on the scripts being executed in a certain order. ![]() define ( 'CUSTOMTAGS', true ) Then, you will update functions.php page by adding following code. If it is for our plugin, then two things happen. This function first checks the JavaScript handle. Here is a technique to do it with any WordPress version 4.1 and better. When adding JavaScript in WordPress, it sometimes is necessary to add attributes such as async and defer to the
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |