Limited time sale! Use the code LIFETIME at checkout and get 20% off our limited-time lifetime plans.
WPCodeBox Documentation
< All Topics

How to add external JS code to your WordPress site

WPCodeBox makes it easy to add external JS code to your site. This is useful when you want to include 3rd party libraries from external CDNs. 

To enqueue external JS code, we are going to use WordPress native functions. So, first, we create a PHP snippet, and we set it to run on the page we want the external JS code to be included.

The following code will enqueue an external js file:


add_action('wp_enqueue_scripts', function(){
wp_enqueue_script( '[script_name]', '[script_url]');

Make sure to replace the [script_name] with a name of the script (lowercase characters with no spaces, eg new_jquery_version).
Also, [script_url] is the URL to the external script source (eg.

This will allow registering external JS scripts the WordPress way.

Previous How to add external CSS code to your WordPress site
Next How to add Facebook Pixel to your WordPress site
Copyright © 2022 WPCodeBox SRL. All other trademarks are the property of their respective owners
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram