Css 为什么添加wp_页脚或页眉会正确停止404寻呼机渲染?

Css 为什么添加wp_页脚或页眉会正确停止404寻呼机渲染?,css,wordpress,.htaccess,http-status-code-404,Css,Wordpress,.htaccess,Http Status Code 404,我在本地机器上有这个基本的404页面 我已编辑了我的.htaccess: ErrorDocument 404 /wordpress/wp-content/themes/test_theme/404.php 404页面确实可以正常工作并打开,但是当我添加我的wp_head()时它会断开。背景色仍然正确显示,但页面的其余部分失败 <!DOCTYPE html> <html lang='en-gb'> <head> <title>404 Error&l

我在本地机器上有这个基本的404页面

我已编辑了我的.htaccess:

ErrorDocument 404 /wordpress/wp-content/themes/test_theme/404.php
404页面确实可以正常工作并打开,但是当我添加我的
wp_head()时它会断开。背景色仍然正确显示,但页面的其余部分失败

<!DOCTYPE html>
<html lang='en-gb'>
<head>
<title>404 Error</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<link href='http://fonts.googleapis.com/css?family=Monoton' rel='stylesheet' type='text/css'>
<style type="text/css">
body {
  background-color: #111;
}

.board {
  position: absolute;
  top: 50%;
  left: 50%;
  height: 150px;
  width: 500px;
  margin: -75px 0 0 -250px;
  padding: 20px;
  font: 75px/75px Monoton, cursive;
  text-align: center;
  text-transform: uppercase;
  text-shadow: 0 0 80px red, 0 0 30px firebrick, 0 0 6px darkred;
  color: red;
}

#error {
  color: white;
  text-shadow: 0 0 80px white, 0 0 30px green, 0 0 6px blue;
}

 </style>
 <?php wp_head(); ?>
</head>
<body>
<div class="board"><p id="error">error</p><p id="code">404</p></div>
<h2><?php _e( 'This is somewhat embarrassing, isn’t it?', 'twentythirteen' ); ?></h2>
<p><?php _e( 'It looks like nothing was found at this location. Maybe try a search?', 'twentythirteen' ); ?></p>
<?php get_search_form(); ?>
</body>
</html>

但是添加
wp_footer()
也会破坏页面,就好像wordpress正在破坏我的404页面。

问题是您直接加载主题文件,而这并没有加载所有必要的wordpress文件,因此无法运行。因此,
wp_footer()
wp_头()函数不存在

WordPress会自动处理404错误,所以删除添加到.htaccess文件中的行,它就会正常工作


请务必阅读本文:

我想cale_b已经回答了您的问题,但为了提供更多信息,wp_head和get_footer是wordpress函数,因此您不能在不调用get_header或包含在wp_blog_header.php中的情况下调用它们

如果您只需要函数而没有获得整个头(可能您想要自定义头,或者根本不需要头),我建议在php文件的最顶端包含wp_blog_header.php,或者至少在任何wordpress函数之前


wp_blog_header.php可以在wordpress安装的根目录中找到。

好的,但现在我只收到标准的404错误消息。我已经查看了wordpress 404页面,我尝试使用他们的示例,但仍然不起作用。你只需要按照制作其他页面的方式来制作。已经有一个模板-所以只需编辑它,而不是构建一个新页面。您可以将该页面作为目标,将CSS与其他内容一起放入style.CSS中。@sheriffderek这是一个自定义主题,没有404模板,因为我还没有创建模板。如果我真的创建了一个404页面,我怎么告诉wordpress这个页面是我的404页面呢?它会知道的。我也总是从头开始创作我的主题。如果出现问题,它会在页面中搜索,如果有404.php,则会找到404.php。此外,无空缺脚本的大小仅为4k或更少。不值得为特定于页面的加载请求额外的服务器请求。把它放在所有其他脚本上。非常感谢你的提示,我不知道。
if(is_404()){               wp_register_script('404',get_template_directory_uri().'/js/jquery.novacancy.min.js', false, NULL, true);
    wp_enqueue_script('404');
}