0

After upgrading WordPress from 4.9.13 to 5.3.2 some scripts on website stop working in weird way... (example for clndr.js).

All scripts are added via wp_register_script and wp_add_inline_script WordPress' functions.

At bottom of <body> there are three scripts as always:

<script type='text/javascript' src='http://example.com/clndr.min.js'></script>
<script type='text/javascript' src='http://example.com/calendar.js'></script>
<script type='text/javascript'>
    var calendar = create_calendar();
</script>

Relevant part of calendar.js

function create_calendar()
{
    var calendar = $('#Calendar').clndr({
        // clndr options
    });

    return calendar;
}

All scripts should run in right order, but they are not working and in browser console I have this error: TypeError: $(...).clndr is not a function

Also, changing call to create_calendar in this way:

window.addEventListener("load", function(){
    var calendar = create_calendar();
});

changes only order of errors in console.

If I understand everything correctly, this should just work.. Any ideas? Or hints how to debug this?

2

1 Answer 1

-1

According to @fuxia comment:

Solution is removing jQuery included by WordPress just before register/enqueue custom jQuery (see https://stackoverflow.com/a/27048128).

So if you include some jQuery on your own, then add

wp_dequeue_script('jquery');
wp_deregister_script('jquery');

just before register/enqueue custom jQuery script in wp_enqueue_scripts action.

Or if you want jQuery included by WordPress just remember, that it's in no-conflict mode and $ is undefined. See https://wordpress.stackexchange.com/a/2896/182809 for more details.

1
  • -1 for what exacly?
    – acinis
    Commented Feb 17, 2020 at 17:57

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.