What's the best way to add jQuery to a WordPress underline (_s) theme?

This may seem basic, but I'm not sure how to add jQuery (using CDN) to the Underline WordPress Theme for Beginners . I was looking a little, but did not find anything, so I was hoping that someone could get an answer from me?

Thank you in advance!

+6
source share
3 answers

The best way is to use the Wordpress wp_enqueue_script() functions.php in your functions.php theme of the created underline theme.

Find the <THEME_NAME>_scripts (where <THEME_NAME> is the name of your theme when creating it on the Underscores website) and add the code below under the <THEME_NAME>_scripts (before any other wp_enqueue_script )

 // deregister default jQuery included with Wordpress wp_deregister_script( 'jquery' ); $jquery_cdn = '//ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js'; wp_enqueue_script( 'jquery', $jquery_cdn, array(), '2.2.4', true ); 
+10
source

The underline does not get stuck in javascript, which relies on jquery. Thus, the default installation will not load the default jQuery in WordPress without installing it as a dependency when inserting a javascript file using wp_enqueue_script .

An example of loading bootstrap in underlining and loading jquery from WordPress

wp_enqueue_script('bootstrap', get_template_directory_uri().'/assets/javascripts/bootstrap.min.js', array('jquery'),'v3',true);

You can do the same with a jquery file from a CDN registered in WordPress

+1
source

You can use this snippet in any header.php or footer.php file:

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 

This uses jQuery hosted by Google.

Note. WordPress comes with jQuery, so if you use Underscores as a WordPress theme, then jQuery will already be queued.

Link: https://developers.google.com/speed/libraries/devguide#jquery

0
source

Source: https://habr.com/ru/post/972950/


All Articles