【问题标题】:adding template from plugin to wordpress contained with built in wordpress functions将模板从插件添加到包含内置 wordpress 功能的 wordpress
【发布时间】:2020-09-19 00:09:49
【问题描述】:

我通过以下代码将我的自定义模板从我的插件添加到 wordpress

function override_single_template( $single_template ){
    global $post;
    if ($post->post_type == "recipes"){
        $single_template  = plugins_url('/recipe-single-page-template.php',__FILE__);
    }
    return $single_template;
}
add_filter( 'single_template', 'override_single_template',10);

但我不能在我的模板中使用 get_header() 或 get_footer() 函数或任何其他 wordpress 函数,并且出现以下错误:

Uncaught Error: Call to undefined function get_header()

我应该怎么做才能使用 wordpress 内置功能?

【问题讨论】:

    标签: php wordpress plugins


    【解决方案1】:

    我找到了答案 我应该将 wp-load.php 文件添加到我的模板中以使用 wordpress 功能 只需将以下代码添加到标题中,现在就没有问题了

    require_once("../../../wp-load.php");
    

    【讨论】:

      猜你喜欢
      • 2012-08-08
      • 1970-01-01
      • 2020-09-24
      • 1970-01-01
      • 2013-06-03
      • 2023-03-08
      • 1970-01-01
      • 2016-05-02
      • 1970-01-01
      相关资源
      最近更新 更多