I keep getting this error “$.cookie is not a function” when trying to implement jQuery cookies.
As far as I can tell I’m implementing the plugin correctly:
First loading:
/wp-content/themes/divi-child/js.cookie.js
Then loading my custom code:
/wp-content/themes/divi-child/custom.js
But using the following in ‘custom.js’:
jQuery(document).ready(function($) {
$.cookie("test", 1);
});
…creates this error in console:
custom.js:2 Uncaught TypeError: $.cookie is not a function
at HTMLDocument. (custom.js:2)
Site can be previewed here:
http://dtodd.co.uk/
2
Answers
$.cookie
is not a standard jQuery function and the plugin needs to be downloaded here. Make sure to include the appropriate tag where necessary. Can be downloaded from: https://github.com/carhartl/jquery-cookieWhen including the cookie script, make sure to include jQuery FIRST, then the cookie plugin.
entirely probably that WP has the new version of the cookie.js included, and downloaded from here:
https://github.com/js-cookie/js-cookie
and the answer can be seen in this post:
https://stackoverflow.com/a/38492574/1470145