Answer the question
In order to leave comments, you need to log in
How to include jquery in wordpress?
I'm learning Wordpress and just got bored with jquery. In footer.php connected via cdn, but the jquery code did not work. Then in functions.php I wrote wp_enqueue_script( 'jquery'); The script was included in head. But the code still didn't work. Tried to re-register jquery using cdn. As a result, left wp_enqueue_script( 'jquery'); And I wrapped the whole jquery code in jQuery(document).ready(function($) {. Part of the jquery code worked, but the click event did not work as it should, the page just reloads, although I have .on("click", function( e) {
e.preventDefault(); ... And in normal layout everything worked fine. But with wordpress you can't just include jquery to make it work fine.
Answer the question
In order to leave comments, you need to log in
1) scripts and styles are connected via functions.php
2) jQuery is already in the VI, if you want to remove it and add your version (more recent for example), then first do wp_deregister_script()
Example:
function register_styles_scripts() {
wp_deregister_script('jquery');
wp_register_script('jquery', get_template_directory_uri() .
'/js/jquery-3.2.1.min.js');
wp_enqueue_script('jquery');
}
add_action('wp_enqueue_scripts', 'register_styles_scripts');
$.noConflict();
jQuery( document ).ready(function( $ ) {
.........
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question