As per WP Code Snippet blog, it looks like this is one way:
Add this code snippet to your functions.php file.
// add async and defer to javascripts
function wcs_defer_javascripts ($url)
{
if (strpos($url, '.js') === FALSE) {
return $url;
}
if (strpos($url, 'jquery.js')) {
return $url;
}
return "$url' async onload='myinit()";
}
add_filter('clean_url', 'wcs_defer_javascripts', 11, 1);
Related Posts:
- How can I reduce the amount of files loaded/included per plugin?
- Prevent CSS/JS loading when plugin is not used
- Eliminate Render blocking CSS?
- Restricting a Plugin to Only Load its CSS and JS on Selected Pages?
- How can I make content disappear when a user logs in?
- W3 Total Cache: Load CSS asynchronously for better PageSpeed score? [closed]
- prettyPhoto media loading very slowly in Chrome
- How to load plugin after page is loaded – pagespeed issues
- Is there an earlier hook than login_head or login_enqueue_scripts?
- Can someone please tell me what is wrong with my plugin?
- Redirect to another page using contact form 7? [closed]
- how to prevent all css and javascripts files from loading
- How to execute a plugin on a single page only?
- get specific value of a array | PHP
- Is wp_deregister_script the best way to deal with unneeded plugins in a page?
- CSS/JS files in WordPress
- How do I override all stylesheets and scripts without a plugin
- uncaught TypeError: Cannot read properties of null (reading ‘classList’) custom plugin
- How do I minify a plugins CSS/JS code?
- Custom Plugin scripts from admin working in frontend
- How to remove Unused CSS From a WordPress Theme?
- Overriding inline !important CSS with Javscript code snippet with media query
- Speeding up WordPress on a Local Network
- Caching of combined CSS and JS fails because of losing MIME types through combining by PHP
- Speed issues because of CSS & JavaScript
- Best use adding user generated JS/CSS to a theme with a plugin
- How to set up php,javascript and css to allow for our finished product to be displayed within a page?
- Possible jquery / library conflict in plugin usage
- contact 7 plugin stops some pages from working properly
- Plugins to generate CSS Sprites? [closed]
- Element works, but not on wordpress site [duplicate]
- Sudden ERR_HTTP2_PROTOCOL_ERROR on every JS and CSS files loads
- How to include code only on specific pages?
- For performance is it better to build custom functionality into the theme or a plugin
- WordPress tips for speed and performance [closed]
- Using tabs for wordpress plugin
- Do Plugins effect site loading time?
- Why is the unrendered widget number `__i__` showing up in the JavaScript but not in the HTML?
- How to Reload the Dashboard After Clicking Update in Quick-Edit?
- WordPress Plugin Look & Feel
- Add CSS class to add-to-cart button, Woocommerce [closed]
- How to load all plugins CSS after child theme CSS?
- White text on white background in TinyMCE when wp_editor is called in WP 3.9
- I need to generate the CSS for my plugin from a function, how do i map a request to a function in the front-end?
- What’s the best plugin for allowing javascript in a post or page? [closed]
- Is it possible to filter the wp_footer() scripts, read the content, and insert them inline?
- Override Theme CSS with CSS from a plugin
- How to see list of plugins
- Disable / Deregister all JS from all plugins
- Passing RichText attributes to function onChange
- Gutenberg List Extension Block
- JQuery not working in my plugin [closed]
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- How to disable specific plugin in mobile version?
- Correct way to perform non-cacheable DB query
- Updating the Drag-To-Share eXtended share URLs?
- WPBakery JS composer unused css [closed]
- How to tie dark mode with prefers-color-scheme webkit? [closed]
- Changing “elapsed time” to “time remaining” on MP3-jPlayer audio player with CSS or PHP changes
- Removing included CSS file that doesn’t exist
- add input in custom javascript from WordPress pages/posts
- Ability to automatically redirect a URL
- accessing wp.media api from a tinymce plugin
- How to load wp_editor via AJAX
- Adding CSS to custom post type admin page causes error
- Namespaced shortcode?
- Edit External CSS
- Why Do I get “wp_remote-get: could not handle for fopen()”?
- JavaScript in a PHP plugin
- Combining several CSS files into one for optimization
- How do I add some javascript validation to the admin interface form’s onsubmit?
- How use wp media upload liberary in react components?
- How to use custom Javascript code inside a plugin?
- Executing Javascript in Plugin
- Add background image/layout for single page?
- What’s the default setting for including a in a post
- Code for unique user visit count on every page WordPress
- Set Button in PluginDocumentSettingPanel Content (WordPress Gutenberg)
- Fixed: Console.log twice in the edit function
- Javascript embedded disappears for editors
- Trouble with AJAX using GET
- front end editor creation for Restropress plug in – displaying information from a WP admin area, on a different URL
- How to get Angular app working in WordPress plugin?
- Custom Field used to allow a Free Story; no longer works
- How to change the width of certain paragraph or header blocks?
- Create a form and have custom menu display based on user answers?
- Enabling plugin on specific pages and subpages
- How to print shortcode with js in visual composer?
- Very Slow loading. Plugins report provided by P3 included
- Display alt text as tool tip on page
- Can’t insert files in other inputs
- Is it possible to run javascript on plugin deactivated?
- How do I output user_registered time in my correct timezone?
- Ajax in Plugins: returns the whole page
- How to tweak a plugin without preventing it from updating
- Trying to disable all notifications except for one on woocommerce checkout page with css [closed]
- Defer parsing of JavaScript [duplicate]
- How do I put a word-press blog into my static site without installing wordpress on server?
- how to embed a crop feature for cropping images uploaded by the user
- Select posts from list and add them in a new list