1

According to wpdevsolutions the correct way to load CDN javascripts in Wordpress is like this:

function theme_name_scripts() {

        wp_enqueue_script( 'pushy', '//cdnjs.cloudflare.com/ajax/libs/pushy/1.1.0/js/pushy.min.js' );
}

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

The question I have is what do I do if the script require jQuery to be loaded?

This does not seem to work.

wp_enqueue_script( 'pushy', '//cdnjs.cloudflare.com/ajax/libs/pushy/1.1.0/js/pushy.min.js', array(), '', true );

The console gives me: Uncaught ReferenceError: jQuery is not defined

Most of the relevant answers here seem to be fairly outdated or incorrect.

1

You need to use it with jQuery like this:

    wp_enqueue_script( 'pushy', '//cdnjs.cloudflare.com/ajax/libs/pushy/1.1.0/js/pushy.min.js', array( 'jquery' ) );
  • How can I load the js in the footer? – Arete Mar 10 '17 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.