1

I am trying to add jquery to my wordpress theme. I have used this code

function theme_name_scripts() {

    wp_enqueue_script( 'jquery',true);
}

add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );

But it is showing at head section . Not in footer section. What is the reason?

Bir
  • 794
  • 1
  • 15
  • 31

2 Answers2

0

Try replacing:

wp_enqueue_script( 'jquery',true);

With this

wp_register_script('jquery', get_template_directory_uri() . '/js/jquery.js', false, null, true);
wp_enqueue_script('jquery');

All that is saying is load the the JS file called jQuery that can be found in the 'js' folder of your theme folder.

Although I would always load in Google's CDN version as recommended here:

EDIT

Alternatively, you could try putting a number at the end of the function line...like this:

wp_enqueue_script( 'jquery',true,11);

EDIT Maybe try this approach: How can I include Jquery in my Wordpress footer?

Community
  • 1
  • 1
egr103
  • 3,858
  • 15
  • 68
  • 119
0

Why script not showing at footer section in wordpress?

Because it's already registered for header, by default, WordPress does it.

You may use (an easy workaround)

wp_enqueue_script('jquery','/wp-includes/js/jquery/jquery.js','','',true);

You can't omit optional parameters like you did in here wp_enqueue_script( 'jquery',true); and following won't work

wp_enqueue_script('jquery','','','',true);

Also remember that, this ($in_footer, to put the script in footer) requires the theme to have the wp_footer() template tag in the appropriate place. Read this article.

Also, you may use

wp_deregister_script( 'jquery' );
wp_register_script(
    'jquery',
    // you can use "http://code.jquery.com/jquery-latest.min.js" for latest version
    /wp-includes/js/jquery/jquery.js,
    false,
    false,
    true
);
wp_enqueue_script( 'jquery' );

Also, check this generator, it gave me following code generated by options I've chosen

// Register Script
function custom_scripts() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'http://code.jquery.com/jquery-latest.min.js', false, false, true );
    wp_enqueue_script( 'jquery' );
}
// Hook into the 'wp_enqueue_scripts' action
add_action( 'wp_enqueue_scripts', 'custom_scripts' );

You can generate your own code using this tool very easily.

The Alpha
  • 143,660
  • 29
  • 287
  • 307