有没有办法自动运行get_header()
在模板和的开头get_footer()
最后呢?
目前,我的代码对这些调用过于重复。
我一直在寻找一种方法来做到这一点,但我在谷歌上找不到。
有没有办法自动运行get_header()
在模板和的开头get_footer()
最后呢?
目前,我的代码对这些调用过于重复。
我一直在寻找一种方法来做到这一点,但我在谷歌上找不到。
正在查看wp-includes/template-loader.php
… 似乎有一种方法:
if ( $template = apply_filters( \'template_include\', $template ) )
include( $template );
您可以挂接到该过滤器中,处理回调函数中的include并返回FALSE
.未测试的示例代码:
add_filter( \'template_include\', function( $template ) {
get_header();
include $template;
get_footer();
return FALSE;
});
@scribu 提出了一种减少WordPress模板中代码重复的方法theme wrappers, 这就实现了你想要的。这个roots theme 使用稍微修改的version of this method.
我正在尝试创建一个主题设置导出脚本,该脚本base\\u 64对主题选项进行编码,并允许用户将其下载为文本文件。我看到一个帖子(What is the best way to export and import theme options?) 这涉及检查查询变量,然后使用“template\\u redirect”操作重定向用户。然而,看起来这个操作只在站点的前端可用(不在管理中)。将操作添加到选项框架的构造函数中并没有任何作用。我可以通过将我的函数绑定到“admin\\u init”来启动它,但到那时,