0

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);
3
  • 5
    Possible duplicate of How do I add a simple jQuery script to WordPress? Commented Aug 16, 2018 at 7:26
  • right now, you have jquery as a dependancy to enqueue jquery, which has a dependancy to enqueue jquery, which.... Commented Aug 16, 2018 at 7:56
  • or are you trying to enqueue jquery two times? why does jquery2 need jquery to be loaded? Commented Aug 16, 2018 at 7:59

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.