This will improve your speed score when testing with Google page speed or Yslow. Google and other search engines are now considering page speed as one of the performance matrices when displaying search results. This means that websites that load faster will appear more prominently in search results.
The Proper Way of Adding Scripts in WordPress
WordPress has a powerful enqueuing system which allows theme and plugin developers to add their scripts in queue and load them as needed. Enqueuing scripts and styles properly can significantly improve your page load speed.
.js file and place that
.js file in your theme’s
functions.php file and add this code:
In this code, we have used wp_register_script() function. This function has the following parameters:
To add the script in the footer or bottom of a WordPress page, all you need to do is set the
$in_footer parameter to
We have also used another function
get_template_directory_uri() which returns the URL for the template directory. This function should be used for enqueuing and registering scripts and styles in WordPress themes. For plugins we will be using
Register and Enqueue Scripts
.js file. Then use
Editor’s note: It is important to understand that when you make changes to the core files and update the plugin, then your changes will not be overridden. A better way of doing this would be to deregister the script and re-register it from your theme’s functions.php file.