sadiq
sadiq

Reputation: 3

add jquery to wordpress in function?

Possible solution to my problem in Wordpress I called jquery in the function but the problem does not work and does not appear in the source bar and I call the rest of the files in the same way and work normal

wp_enqueue_script('jquery2', get_template_directory_uri() . '/js/jquery-2.2.0.min.js', array('jquery'), false, true);

Upvotes: 0

Views: 64

Answers (2)

Pallavi
Pallavi

Reputation: 31

se this in your functions file:

// Enqueue Scripts
function wpse78227_enqueue_scripts() {
    wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'wpse78227_enqueue_scripts' );

Next for including that script you need to follow teh below steps:

  1. Create a new file in your theme for the script (i.e. jquery.show-hide.js)
  2. Copy that jQuery function into this new file
  3. Enqueue the script file as you would any other

This would then give you:

// Enqueue Scripts
function wpse78227_enqueue_scripts() {
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-show-hide', get_template_directory_ui() . 
'/js/jquery.show-hide.js', array( 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'wpse78227_enqueue_scripts' );

Your script file might now be located in /wp-content/themes/your-theme-name/js/jquery.show-hide.js.

Upvotes: 0

iPraxa Inc
iPraxa Inc

Reputation: 556

Please try with this code

if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 1);

function my_jquery_enqueue() {

   wp_deregister_script('jquery');

   wp_register_script('jquery', get_template_directory_uri() . '/js/jquery-2.2.0.min.js', false, null);

}

You need to de_register current jQuery to avoid multiple jquery.

Upvotes: 1

Related Questions