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='.min.js'></script>
<script type='text/javascript' src='.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?
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/clndr.min.js'></script>
<script type='text/javascript' src='http://example/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?
Share Improve this question edited Feb 16, 2020 at 16:52 acinis asked Feb 16, 2020 at 15:51 acinisacinis 12 bronze badges 2 |1 Answer
Reset to default -1According to @fuxia comment:
Solution is removing jQuery included by WordPress just before register/enqueue custom jQuery (see https://stackoverflow/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/a/2896/182809 for more details.
$
in WordPress. See wordpress.stackexchange/questions/2895/… – fuxia ♦ Commented Feb 16, 2020 at 15:55