Note that there are some explanatory texts on larger screens.

plurals
  1. POIs jQuery automatically enqueued in Wordpress 3.6
    text
    copied!<p>Before, to include jQuery in Wordpress you had to do this:</p> <pre><code>wp_enqueue_script('jquery'); </code></pre> <p>But, as a method to make sure jquery was not already loaded, some people would do this:</p> <pre><code>function sp_load_jquery() { // only use this method is we're not in wp-admin if ( ! is_admin() ) { // deregister the original version of jQuery wp_deregister_script('jquery'); // register it again, this time with no file path wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null); // add it back into the queue wp_enqueue_script('jquery'); } } add_action('template_redirect', 'sp_load_jquery'); </code></pre> <p>Which is frowned upon by many, who argue Wordpress loads jQuery in noConflict mode.</p> <p>But, my ultimate question is, it seems that in Wordpress 3.6+ jQuery is automatically enqueued by Wordpress. Can someone tell me if this is the case?</p> <p><strong>EDIT</strong></p> <p>Ok, so with the help and answer below, this is what I now have:</p> <pre><code>function sp_load_jquery() { if ( ! is_admin() &amp;&amp; !wp_script_is( 'jquery' ) ) { wp_deregister_script('jquery'); wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js", false, null); wp_enqueue_script('jquery'); } } add_action('wp_enqueue_scripts', 'sp_load_jquery'); </code></pre> <p>The add_action loads the sp_load_jquery function when Wordpress fires the wp_enqueue_scripts hook. The function then checks if user is not viewing the admin (as jQuery is auto loaded there), and also checks that jQuery has not been loaded using the Wordpress <code>wp_script_js()</code> function. The function then de-registers jQuery with Wordpress, re-registers it using Google's CDN and then sends the Google version back to the queue.</p> <p>But, if you don't want to use Google's CDN, just do this:</p> <pre><code>function sp_load_jquery() { if ( ! is_admin() &amp;&amp; !wp_script_is( 'jquery' ) ) { wp_enqueue_script('jquery'); } } add_action('wp_enqueue_scripts', 'sp_load_jquery'); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload