使用插件在登录页面上添加新页眉/页脚

时间:2018-05-14 作者:Johan Dahl

我需要从插件中调用特定登录页的自定义页眉/页脚。我该怎么做?我知道我可以在我的主题中创建一个模板,并通过向get_header()/get_footer().

然而,我想从插件中提供页脚/页眉,因为我经常将与自定义登录页相关的所有内容放在插件中。我不想在每个登录页的主题中都有一个页脚模板。

这方面的最佳解决方案是什么?我不想用CSS隐藏内容。

以下是我的landingpage插件的基本外观要点:

https://gist.github.com/kyotoprotokollet/8b6e3f978ce3bd237e359e98cca151f1

1 个回复
SO网友:cjbj

您可以截取WordPress将用于template_include 滤器像这样:

add_filter (\'template_include\',\'wpse303537_plugin_template\', 10,1);
function wpse303537_plugin_template ($template) {
  if (is_front_page)
    $template = plugin_dir_path( __FILE__ ) . \'/my-template.php\';
  return $template;
  }
或者,您可以在主题中为登录页包含一个几乎为空的模板,并通过get_header.

结束