我有Wordpress,我想将其页眉和页脚添加到不同的脚本模板文件 . 最简单的方法就是复制并粘贴html代码,但之后我将松开所有动态变化等等 .

Wordpress提供了一种在外面添加页眉和页脚的方法,其中包括以下两个文件:

<?
require('wp-load.php');
include('wp-content/themes/theme/header.php');
?>

但这显示我重新声明的函数错误0两个函数都是同名,所以这就是冲突 . 由于我真的无法编辑函数名称,我正在寻找不同的解决方案 .

所以我想出了在不同文件(test.php)中执行脚本,然后将纯html添加到我的头文件中(header.html - 带有php解析的文件)

所以我做了这样的事情:

<?
ob_start();
require('wp-load.php');
include('wp-content/themes/theme/header.php');
$header_output = ob_get_contents();
ob_get_clean();
?>

我将它包含在我的header.html中,如下所示:

<?
include('test.php');
echo($header_output);
?>

但遗憾的是它没有帮助 - 仍然存在冲突,因此它不包括已执行的脚本(html),但仍然具有功能......

我已经测试了test.php,如下所示,看它是否有效:

<?
ob_start();
require_once('wp-load.php');
include_once('wp-content/themes/theme/header.php');
$header_output = ob_get_contents();
ob_get_clean();

echo($header_output);
?>

然后为了测试我将$ header_output保存到一个文本文件(使用fwrite()) - 它工作,纯HTML!所以我认为我的包含有问题......

当然,我每次都可以生成文本文件的新内容并将其包含在我的header.html中,但我认为这样做无效 .

我可以做些什么来使我的header.html不包含wp-load.php?