致命错误:未捕获的错误:调用未定义的函数get_header()

huangapple go评论73阅读模式
英文:

Fatal error: Uncaught Error: Call to undefined function get_header()

问题

我正在处理一个WordPress网站,并遇到了一个关键错误:我已经创建了一个header.php文件,并尝试使用get_header()函数将页眉导入到我的所有页面中。在我的index.php页面中,它工作得很完美,但在我的所有其他页面中,我收到一个错误消息,其中说“致命错误:未捕获的错误:调用未定义的函数get_header()”。出于实验目的,我的index.php页面中的代码与我的所有其他.php页面中的代码相同。我做错了什么?以下是我的一个页面“feedback.php”的代码:

<!DOCTYPE html>
<html>
<head>
<!-- 从header.php导入页眉 -->
<?php get_header() ?>    
<title>首页</title>
<link href="https://fonts.googleapis.com/css2?family=Notable&display=swap" rel="stylesheet">
</head>
<body>
<h2>你好,世界</h2>
</body>
</html>
英文:

I am working on a WordPress website and have come across a critical error:I have created a header.php file and tried using the get_header() function to import the header into all of my pages. In my index.php page it works perfectly, but in all of my other pages, I get an error message saying “Fatal error: Uncaught Error: Call to undefined function get_header()”. For experimental purposes, the code in my index.php page is the same as in all of my other .php pages. What am I doing wrong? Here Is the code for one of my pages “feedback.php”:

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;!-- Import Header from header.php --&gt;
&lt;?php get_header() ?&gt;    
&lt;title&gt; Home &lt;/title&gt;
&lt;link href=&quot;https://fonts.googleapis.com/css2?family=Notable&amp;display=swap&quot; rel=&quot;stylesheet&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h2&gt; Hello World &lt;/h2&gt;
&lt;/body&gt;
&lt;/html&gt;

答案1

得分: 0

以下是翻译好的部分:

"It sounds like feedback.php is being accessed directly, which doesn't load WordPress. This is why get_header() is undefined."

根据听起来的情况,feedback.php 正在直接访问,这不会加载 WordPress。这就是为什么 get_header() 未定义。

"Depending on the purpose of feedback.php, you may want to use it as a page template (most common), or load WordPress on top of it."

根据 feedback.php 的用途,您可能希望将其用作页面模板(最常见),或在其之上加载 WordPress。

"For using as a page template (most use-cases, and likely yours), read this official WordPress Developer Resource article: https://developer.wordpress.org/themes/template-files-section/page-template-files/."

如果要用作页面模板(大多数用例,可能是您的情况),请阅读此官方 WordPress 开发者资源文章:https://developer.wordpress.org/themes/template-files-section/page-template-files/。

"If you do want to load WordPress on top of the file (uncommon), then you'll need to include the wp-load.php file (root of WordPress install) at the top of the file."

如果您确实想要在文件顶部加载 WordPress(不常见),那么您需要在文件顶部包含 wp-load.php 文件(WordPress 安装的根目录)。

英文:

It sounds like feedback.php is being accessed directly, which doesn't load WordPress. This is why get_header() is undefined.

Depending on the purpose of feedback.php, you may want to use it as a page template (most common), or load WordPress on top of it.

For using as a page template (most use-cases, and likely yours), read this official WordPress Developer Resource article: https://developer.wordpress.org/themes/template-files-section/page-template-files/.

If you do want to load WordPress on top of the file (uncommon), then you'll need to include the wp-load.php file (root of WordPress install) at the top of the file.

huangapple
  • 本文由 发表于 2023年6月6日 02:09:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76408973.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定