英文:
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”:
<!DOCTYPE html>
<html>
<head>
<!-- Import Header from header.php -->
<?php get_header() ?>
<title> Home </title>
<link href="https://fonts.googleapis.com/css2?family=Notable&display=swap" rel="stylesheet">
</head>
<body>
<h2> Hello World </h2>
</body>
</html>
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论