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
- opening and closing elementor-widget-container
- How to resolve Multisite Speed issues
- Disable submit button order
- Add logo to admin menu in my plugin
- I would like to remove date display on photo preview
- Conditional custom redirect
- At a Loss on over Page Peel Plugin Customization [closed]
- Executing Javascript in Plugin
- Custom CSS not being added by plugin
- Blocking Plugin Css to load custom in template directory
- Social share buttons text shows up on post excerpts
- Meta slider plugin only works after first refresh – Object has no method ‘flex slider’
- Load CSS files in header of Bones theme?
- Block wordpress style for my plugin admin page
- Not able to override plugin’s default css rules
- The Events Calendar Plugin – List View Background Colour Issue [closed]
- how to request a script more than once in wordpress
- insert an html tag using php plugin
- Add background image/layout for single page?
- How to turn off automatic operation for Nivo Slider?
- How to enqueue some javascript source once per page
- Best practice when modifying plugins CSS [duplicate]
- How to theme code blocks formatted by the prettify.js embedded with WP-Markdown?
- should i use GLOB_ONLYDIR to hook add-ons for wordpress plugin
- Dropdown menu on click change
- JS Plugin not executing the js correctly. Trying to make all internal links scroll smoothly
- Call javascript functions from each page
- Javascript from Easy-Fancybox place into footer
- Minification Plugins break my website
- What’s the default setting for including a in a post
- Wp-minify doesn’t seem to minify my JS code
- How do I work with the SlideDeck plug-in?
- Why is adoptStyles-css stylesheet link added to every page?
- Theme deactived html and css styling on home page posts
- Plugin Admin panel checkbox unchecked after submit
- Code for unique user visit count on every page WordPress
- Themes conflicts and overrides my WordPress Support widget Plugin styles
- Directorist – Dropdown doesn’t open
- Ajax call not working in wordpress through a plugin
- Send Array from JS to php file then insert it in wp database through a plugin
- Button and Countdown overlapping mobile menu
- Unable to locate inline CSS causing parts of page to be blank
- Set Button in PluginDocumentSettingPanel Content (WordPress Gutenberg)
- Want to create custom design of progress indicator in wpforms
- Strange admin-ajax / CSS / $_SESSION issue
- Two plugins using the same CSS id
- Load CSS before Theme CSS
- Javascript fetch on wordpress plugins not working
- Jquery POST Ajax Return null data in wordpress
- Gutenberg: Prevent links from being clickable in the block. Error: “Cannot destructure property ‘frameElement’ of ‘r’ as it is null.”
- “Disable” specific plugins on certain pages
- How to apply to hide TinyMCE (wp_editor) on button click
- Upload Javascript and json webpage to wordpress
- How to override Plugin javascript function : $(‘body’).on(‘change’,’.class’)
- Connect / Login WordPress Hosted Website or Blog with NodeJs
- Stop a script on a single page
- Menu not closing after clicking – WordPress – Elementor
- login form should redirect to register page for in 1st login next time it should redirected to home page
- is there a way to preload specific images for desktop users only? (excluding mobile users)
- Validating ajax search
- inserting custom css, html and js into the current page as a popup window
- Fixed: Console.log twice in the edit function
- Javascript embedded disappears for editors
- Cannot run script properly with my custom plugin
- How to fetch WordPress database values in JavaScript widget
- Possible way of having multiple Gutenberg instances for a page?
- How to change the WordPress Plugin Watson Assistant Chatbot BOX Size?
- Trouble with AJAX using GET