Theme JQuery inlcusion on WordPress 6.0 always fails

Question

I am writing here because i have WordPress 6.0, i am trying to include JQuery in my theme beacuse i have to start working on a functionality i need. The problem is that JQuery is not loading correctly i guess because in my chrome developer console i got this error:

enter image description here

enter image description here

Jquery is not recognized but i don’t undersand why, because i have always followed WordPress practices and as you can see below in the code apparently there is nothing wrong. WordPress has already its own Jquery, i don’t want an external Jquery library even in CDN, i don’t thin is needed another JQuery.

Here is the code for enqueuing additional js scripts in functions.php:

function load_custom_jquery_edit(){
wp_enqueue_script('jquery');

wp_enqueue_script('customize-jq', 
                    get_template_directory_uri().'/assets/js/customize-jq.js',
                    array('jquery'),
                    "1.1.0",
                    true);
}

add_action('wp_enqueue_scripts', 'load_custom_jquery_edit');

This is my JQuery additional file:

(function($){
$(document).ready(function(){
    //testing example
    $('test-my-new-submit-btn')
    .attr('id','testBtn');

    $('#testBtn').on('click', function(e){
        e.preventDefault();
    
        let success_msg = "success!!!";
        
        alert(success_msg);
                    
        //Other things to do next
    });
});
})(JQuery);

0
francesco 1 month 2022-07-04T11:20:19-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse