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]
- Multiple plugins vs combined one
- How do I sanitize a javascript text?
- How can a Firebase user registration and login be integrated into a WordPress site?
- How do I make my wordpress page more friendly for mobile viewers?
- Custom plugin giving: wp-admin/admin-ajax.php 400 (Bad Request)
- Check javascript file Proper way in functions.php
- how would I include a js file with tags into wordpress?
- Google Maps and Yandex Maps doesn’t work correctly
- Styling readme.html in plugin?
- Creating an Exit Confirmation Popup
- How to override my plugin’s php classes with duplicates that are in my child theme folder
- WordPress takes too much time (100 seconds) to load – Front end and back end
- plugin style conflicts, how to override? [closed]
- Admin Panel pagination link styles
- How to style the RSS wordpress?
- How Do I Figure Out What File(s) to Edit from Looking at the Source Code [closed]
- Change upload folder for a CPT
- Delete mobile menu button [closed]
- Widgets Scripts don’t load – but load when I reload the page
- Using window.onload with Ubermenu
- Stop Plugin from Getting Styles from Other Plugin
- How to apply next/previous classes to LIs for pagination links?
- Front-end CSS Library for plugin [closed]
- Infinite scroll messing up nth:of-type
- Wooslider custom css
- Plugin has added weird data in wp_options, set to autoload
- Why does my jQuery plugin show up as text in WordPress?
- Disable submit button order
- Not able to override plugin’s default css rules
- The Events Calendar Plugin – List View Background Colour Issue [closed]
- insert an html tag using php plugin
- Best practice when modifying plugins CSS [duplicate]
- How do I work with the SlideDeck plug-in?
- Why is adoptStyles-css stylesheet link added to every page?
- Themes conflicts and overrides my WordPress Support widget Plugin styles
- Ajax call not working in wordpress through a plugin
- Gutenberg: Prevent links from being clickable in the block. Error: “Cannot destructure property ‘frameElement’ of ‘r’ as it is null.”
- Menu not closing after clicking – WordPress – Elementor
- is there a way to preload specific images for desktop users only? (excluding mobile users)
- Cannot run script properly with my custom plugin
- how i retreive the post content while editing it in real time however the editor is tinymce or gutenberg
- How to properly enqueue jQuery knob on WordPress without conflict?
- How to get a specific string from a url
- Does anybody know how to insert a complete jquery plugin into a wordpress elementor-page?
- JS working when used normally but not in wordpress
- Use AJAX to fetch Current Post Thumbnail for WordPress when Uploaded throughMedia Uploader Frontend
- Problem with wordpress has_action() function
- wp plugin adds “pagespeed.css” after each css file
- How to disable/enable PHP plugin functionality based on a TinyMCE toggle-button
- How to remove a css class for any wordpress page
- Creating wordpress admin page panel [Theme Option]
- show-hide based on select option jquery wordpress
- Having trouble going from Jfiddle to implementing in WordPress :(
- Media Playlist Plugin
- Is saving multiple options or saving multiple items in one option better?
- Why won’t the Comprehensive Google Map Plugin load?
- Plugin – including external javascript calling google maps
- How to load css files in a specific order
- how woocommerce swatch color name when hovered or selected
- How to create post comparison in wordpress
- How to access values from your own settings page in javascript?
- Refresh server side rendered block in Gutenberg without changing attributes or its content
- How do I call an action hook into wp_ajax hook callback function
- Option value not getting updated until page refresh in WordPress
- I want to display data last 7 days with date wise in chartjs?
- How to create a “Most Popular” & “Latest” TAB in WordPress
- this code is fiven by chat-gtp but nothing match even I key in the value of a cell. help!
- Use custom Javascript for a custom Elementor Widget [closed]
- How can I wordpress cache a database request with no existing plugin?