S
S
Stanislav62020-08-10 18:20:48
WordPress
Stanislav6, 2020-08-10 18:20:48

How to move jquery script to footer in Wordpress?

Guys, help! I move jquery to the footer from the header:

add_action( 'wp_enqueue_scripts', 'jquery_register' );

function jquery_register() {
  wp_deregister_script('jquery-core');
  wp_deregister_script('jquery');

  wp_register_script( 'jquery-core', 'https://code.jquery.com/jquery-2.2.0.min.js', false, null,true );
  wp_register_script( 'jquery', false, array('jquery-core'), null, true );

  wp_enqueue_script( 'jquery' );
}


Everything is fine, the script went to the footer. Next, I include my scripts that depend on jquery:
function main_scripts() {
 	wp_enqueue_script( 'scripts-js', get_stylesheet_directory_uri() . '/assets/js/scripts-js.min.js', array('jquery'), true );
  	wp_enqueue_script( 'scripts-ini', get_stylesheet_directory_uri() . '/assets/js/scripts-ini.min.js', array('scripts-ini'), true );
}

add_action( 'wp_enqueue_scripts', 'main_scripts' );


As a result, jquery, along with my scripts that depend on it, leaves for the header. Where is the mistake?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question