Adding 'Defer' attribute to Scripts added by Plugins in WordPress

How to add ‘defer‘ to scripts added by plugins in WordPress.

In this example, we are adding ‘defer’ ubermenu, cffscripts, and cff_carousel_js JavaScript files.

 

Here is another example.

 

Just remember to add this code to either a site-specific plugin or the functions.php file in the theme.

The “$scripts_to_defer” or “$defer” array contains the ‘admin-bar’ part from the id=”admin-bar-js”  in the example script above.

Updated on Jul 09, 2025