任何将功能挂接到WordPress(不是wp_footer)中的帖子页脚的方法


Any way to hook function into post footer in WordPress (not wp_footer)?

您可以使用以下命令将函数挂接到站点页脚中:

function to_footer() {
  $content = 'I am in the footer';
  echo $content;
}
add_action('wp_footer', 'to_footer');

但是,是否有类似的方法可以在单个页面视图中的帖子页脚(而不是网站页脚)中添加功能?

您可以获得的最接近的(无需更改模板文件)是这个

function to_footer($content) 
{
    return $content . 'I am in the footer';
}
add_action('the_content', 'to_footer');

这将在发布内容后添加您的东西

如果您不介意编辑模板,请尝试以下操作

function alt_footer()
{
    do_action('alt_footer');
}

functions.php您的主题。然后在需要的地方调用模板中的alt_footer(),然后

function to_footer() 
{
    echo 'I am in the footer';
}
add_action('alt_footer', 'to_footer');