WordPress 插件重复操作的问题
我正在编写我的第一个 WordPress 插件,虽然不是最原始的插件,但我仍然无法让它正常工作。问题是,回显页脚中需要回显的内容的函数执行了两次......准确地说,它回显,然后当它读取页脚中的 add_action 时,它会重复该操作。这是代码,如果有人知道我在哪里丢失了它,请告诉我:
function add_copyright(){
$the_array = fof_check_db();
$copyright_message = '<a href="' . $the_array[0] . '">' . $the_array[1] . '</a>';
echo $copyright_message;
}
add_action('wp_footer', 'add_copyright');
另外,我尝试更改返回的回声,但这甚至没有显示任何内容。
欢迎任何帮助
I'm writing my first Wordpress plugin, and though not the most original one, I still cannot get it to work properly. The problem is that the function which echoes what needs to be echoed in the footer is doing it twice... to be precise, it echoes, then when it reads the add_action in the footer it repeats the action. Here's the code, if anyone knows where I'm missing it please let me know:
function add_copyright(){
$the_array = fof_check_db();
$copyright_message = '<a href="' . $the_array[0] . '">' . $the_array[1] . '</a>';
echo $copyright_message;
}
add_action('wp_footer', 'add_copyright');
Also, I tried changing the echo for return, but that didn't even display anything.
Any help will be welcomed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种解释 - 如果主题没有调用 wp_footer() 两次,则调用 add_action() 的代码被调用了两次。这将再次添加该操作,因此调用 do_action() 的 wp_footer() 代码将导致 add_copyright() 被调用两次 - 因为可以将任意数量的回调挂接到一个操作中。
(这也许就是@Frederik询问你在哪里调用add_action背后的想法)
One explanation - if the theme isn't calling wp_footer() twice, is that your code that calls add_action() is being called twice. That would add the action again and hence the wp_footer() code that calls do_action() would cause add_copyright() to be called twice - since any number of callbacks can be hooked into an action.
(That is perhaps the thinking behind @Frederik asking where you call add_action)