在操作调用之间发送变量


Send variables between action calls

我有两个动作:

add_action('init', 'activate');
add_action('wp_footer', 'code');

activate需要设置cookie并在变量$html中生成一些html代码

code然后只需要在wp_footer输出该代码以及其他html代码。我注意到$htmlcode是空的,即使init首先被调用,变量应该用正确的代码填充。调用global $html没有帮助,变量仍然是空的。我如何改变它,使$html有正确的内容,当code被调用,不是空的?

我可以全局定义变量$html,例如:global $html;