2011-05-09 42 views
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; 

回答

1

它出现在Word新闻不缓冲整个页面的内容,而是逐渐将内容发送,因此,我不能在add_shortcode(...)函数发送头

可悲的是,顺序执行不提供在wordpress的API部分... http://codex.wordpress.org/Shortcode_API