dstwfcz1377 2018-10-13 00:26
浏览 40


I'm working on a WordPress plugin and thought that to load front-page.php from my plugin, all I had to do was add it to the root directory like I would in a custom theme, but that has not been the case.

How do I get front-page.php from my plugin to load and override any theme/child themes?

I've tried to use the locate_template override from the codex here, but it only flashes my front-page.php and then defaults to index.php.


Thank you!

  • 写回答

1条回答 默认 最新

  • duanli4146 2018-10-13 00:37

    You could override the template include wordpress function. You do so when using the 'template_include' filter within your themes or plugins 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;

    You also could run trouble when the static frontpage setting is configured. https://codex.wordpress.org/Creating_a_Static_Front_Page

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了
  • ¥15 如何删除这个虚拟音频
  • ¥50 hyper默认的default switch
  • ¥15 网站打不开,提示502 Bad Gateway
  • ¥20 基于MATLAB的绝热压缩空气储能系统代码咨询
  • ¥15 R语言建立随机森林模型出现的问题
  • ¥15 中级微观经济学,生产可能性边界问题
  • ¥15 TCP传输时不同网卡传输用时差异过大
  • ¥15 请各位看看我写的属于什么算法,或者有更正确的写法?