从插件加载front-page.php以覆盖主题

时间:2018-10-13 00:26:46

标签: php wordpress

我正在研究一个WordPress插件,并认为要从插件中加载front-page.php,我要做的就是像在自定义主题中那样将其添加到根目录中,但是并没有情况。

如何从插件中获取front-page.php来加载和覆盖任何主题/子主题?

我尝试使用the codex here中的locate_template替代,但是它只会闪烁我的front-page.php,然后默认为index.php。

有什么想法吗?

谢谢!

1 个答案:

答案 0 :(得分:0)

您可以覆盖包含wordpress功能的模板。在主题或插件function.php中使用“ template_include”过滤器时,您可以这样做。

add_filter('template_include', 'template_override');
function template_override($template) {
  if (is_front_page()) {
    return TEMPLATE_PATH . 'filename.php';
  }
  // default wordpress behavior
  return $template;
}

配置静态首页设置时,您也可能会遇到麻烦。 https://codex.wordpress.org/Creating_a_Static_Front_Page

相关问题