Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enqueue scripts in WordPress from CDN?

I am trying to replicate a pen from codepen for which I have to load 3 script files from CDN and one from the server.

What is the correct syntax to load the scripts from CDN? My codepen

The script files are:

https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js https://cdn.jsdelivr.net/jquery.slick/1.5.9/slick.min.js https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.2/TweenMax.min.js 

Any help will be appreciated.

like image 621
Abhijit Mishra Avatar asked Nov 03 '16 13:11

Abhijit Mishra


People also ask

How do I enqueue a script in WordPress?

To enqueue scripts and styles in the front-end you'll need to use the wp_enqueue_scripts hook. Within the hooked function you can use the wp_register_script() , wp_enqueue_script() , wp_register_style() and wp_enqueue_style() functions.


1 Answers

In your functions.php, using wp_register_script() and wp_enqueue_script()

CSS

wp_register_style( 'Font_Awesome', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css' ); wp_enqueue_style('Font_Awesome'); 

JS

wp_register_script( 'jQuery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js', null, null, true ); wp_enqueue_script('jQuery'); 

Your case

wp_register_script( 'jQuery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js', null, null, true ); wp_enqueue_script('jQuery'); wp_register_script( 'TweenMax', 'https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.2/TweenMax.min.js', null, null, true ); wp_enqueue_script('TweenMax'); wp_register_script( 'Slick', 'https://cdn.jsdelivr.net/jquery.slick/1.5.9/slick.min.js', null, null, true ); wp_enqueue_script('Slick'); 
like image 56
wscourge Avatar answered Sep 29 '22 11:09

wscourge