如何在wordpress中设置cookie? [英] How to set cookie in wordpress?
本文介绍了如何在wordpress中设置cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在wprdpress中设置cookie,但它不工作。这是我的代码
I want to set cookie in wprdpress but its not working.This is my code
add_action('init', 'set_new_cookie');
function set_new_cookie() {
setcookie('cart_item','some value', time() + (86400 * 30), "/");
}
但这不工作。
实际上init钩子不工作。我在这里尝试ajax请求(页面访问者没有登录)。
but this is not working. Actually init hook is not working.I am trying to do ajax request here(page visitors are not logged in).
推荐答案
setcookie('cart_item',$carts,time() + (86400*30),'/');
它的工作对我很好。 /最后是为整个网站设置cookie。
删除/仅设置特定目录的cookie。
Its working fine for me. / at the last is to set cookie for whole site. Remove / to set cookie for particulat directory only.
这篇关于如何在wordpress中设置cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文