0

我正在开发一个 WordPress 插件,并认为front-page.php要从我的插件加载,我所要做的就是像在自定义主题中一样将它添加到根目录,但事实并非如此。

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

我尝试在这里使用 codexlocate_template中的覆盖,但它只闪烁 my然后默认为 index.php。front-page.php

想法?

谢谢!

4

1 回答 1

0

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

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

于 2018-10-13T00:37:37.577 回答