0
运行下面的代码时不会生成错误或警告。
当我尝试在短代码事件中创建cookie时,我刚刚遇到了一个关于WordPress的问题。
在下面的代码中,test1 cookie创建得很好,但是test2 cookie没有创建。
然而,显示的是“Code Ran”。
Wordpress Shortcode setcookie问题
if (! function_exists('cookieset')) :
function cookieset($atts, $content = null) {
extract(shortcode_atts(array(
'name' => 'cookieloc',
'redirect' => '/',
'expires' => '365',
), $atts));
setcookie("test2", 1, time()+3600, "/", ".domainname.com", false, true);
return "Code Ran";
}
endif;
if (! function_exists('cookieloc_action')) :
function cookieloc_action() {
echo add_shortcode('cookieloc', 'cookieset');
setcookie("test1", 1, time()+3600, "/", ".domainname.com", false, true);
}
endif;