在WordPress标题内包含外部PHP



我正在尝试做一些简单的事情,但它行不通。

我有一个自定义的WordPress标头。我需要包括外部PHP类和其他内容。问题是,如果我这样做,页面断开了,它就不再起作用了。

当我尝试在页面模板内"需要"外部PHP脚本时,这不会发生。当我将其包含在 header

中时,就会发生问题。

使其短,我有: header-home.php (标准WordPress主题标头文件,必须包括以下文件(

STEIPPETS.PHP (php类(

header.home.php位于/wp-content/themes/tewseventeen-deventeen/pemplates ...

spenippets.php位于/resources/scripts/snippets.php

位于

也许标题加载与自定义包含物不兼容的东西?

我能够包含一个包含纯HTML元素的外部PHP文件。如果我尝试加载自定义类,则页面只需断开。包含的filepath是正确的,所以这不是问题。

您要需要的所有文件,必须在" functions.php"中执行"/wp-content/themes/twentyseventeen-child/functions.php",然后在文件" header.php"中,您可以实例化对象或调用函数。例如:

function.php

<?php
require("./YourClass.php"); 
function getYourClass() {
  $yourClass = new YourClass();
  var_dump($yourClass); //Verify if it returns data and then delete this line
  return $yourClass;
}

header.php

getYourClass();//Here it brings the object and shows the output.

最新更新