jQuery $.cookie is not a function

前端 未结 7 1589
眼角桃花
眼角桃花 2020-11-27 15:12

I am trying to set a cookie using jQuery:

$.cookie(\"testCookie\", \"hello\");
alert($.cookie(\"testCookie\"));

But when I load my page, I

7条回答
  •  悲&欢浪女
    2020-11-27 15:55

    Check that you included the script in header and not in footer of the page. Particularly in WordPress this one didn't work:

    wp_register_script('cookie', get_template_directory_uri() . '/js/jquery.cookie.js', array(), false, true);
    

    The last parameter indicates including the script in footer and needed to be changed to false (default). The way it worked:

    wp_register_script('cookie', get_template_directory_uri() . '/js/jquery.cookie.js');
    

提交回复
热议问题