• 原森林之家(foresthouse.cn)改为走私范(zousifan.com),只是改个名内容不变。
  • 网站图片自建立开始到19年全部丢失,血的教训时刻备份,多点备份!

解决wordpress地图This page contains the following errors错误的方法

wordpress 8年前 (2016-10-20) 2553次浏览 2个评论 扫描二维码
本文最后更新于2022年5月23日,已超过 1 年没有更新,如果文章内容失效,请 反馈 给我们,谢谢!

今天没事来看看我的站竟然发现网站地图打不开了,很奇怪以前是好好的今天这是怎么了,出现的错误提示如下:


This page contains the following errors:
error on line 2 at column 6: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error.

/sitemap.xml和/sitemap.php提示的都是如上一样的错误。

我用的是地图是网上流传的那种非插件生成的这种:给wordpress添加sitemap.xml地图非插件

检查来检查去都没有什么问题然后又去网上搜索答案找了老半天,总算在一个叫做内存溢出的博客上找到了答案,再次感谢。

正确的方法如下:

打开“wordpress”根目录下的“wp-blog-header.php”文件,在
$wp_did_header = true;
代码下加入以下代码:
ob_start();
在以下代码下
wp();
加入以下代码
ob_end_clean();
最后完整的“wp-blog-header.php”文件因为如以下代码这样:
<?php
/**
 * Loads the WordPress environment and template.
 *
 * @package WordPress
 */

if ( !isset($wp_did_header) ) {

 $wp_did_header = true;
 ob_start();

 require_once( dirname(__FILE__) . '/wp-load.php' );
 ob_end_clean();

 wp();

 require_once( ABSPATH . WPINC . '/template-loader.php' );

}
至此wordpress地图出错的问题就已经解决了。
但是当wordpress有更新的时候它会自动更新上面代码中改动过的几处就又还原了,下面给出几点禁止wordpress自动更新的方法:

第一种:在主题“functions.php”文件中加入以下代码:

//关闭核心程序、主题、插件及翻译自动更新
add_filter( 'automatic_updater_disabled', '__return_true' );

或者根据自身需求选择以下代码:

//核心代码自动更新
add_filter( 'auto_update_core', '__return_false' );


//开发者版本自动更新
add_filter( 'allow_dev_auto_core_updates', '__return_false' );


//小版本自动更新
add_filter( 'allow_minor_auto_core_updates', '__return_false' );


//大版本自动更新
add_filter( 'allow_major_auto_core_updates', '__return_false' );


//插件自动更新
add_filter( 'auto_update_plugin', '__return_false' );


//主题自动更新
add_filter( 'auto_update_theme', '__return_false' );


//翻译文件自动更新,__return_true 为启用,__return_false 为禁用
add_filter( 'auto_update_translation', '__return_false' );

提示:函数参数__return_true 为启用,__return_false 为禁用

第二种:在配置文件中关闭自动更新

在wordpress程序根目录找到wp-config.php文件,添加以下代码:
//关闭核心程序、主题、插件及翻译自动更新
define( 'AUTOMATIC_UPDATER_DISABLED', true );
值得注意的是如果你是一个喜欢折腾经常换主题的话推荐使用第二种方法。我自己用的就是第二种方法,感觉禁止wordpress自动更新就要从系统程序入手的样子。

版权所有丨如未注明 , 均为原创丨本网站采用 BY-NC-SA 协议进行授权 , 转载请注明 出处!
喜欢 (3)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
    仅用来给您发送回复提醒。不会公开!
  • 网址
(2)个小伙伴在吐槽
  1. 楼下是疯子。哈哈
    sendco2019-05-07 17:05 回复来自天朝的朋友 火狐浏览器5.0 Windows 7
  2. 好文章!666,学习了
    jpym82019-05-07 07:06 回复来自天朝的朋友 火狐浏览器5.0 Windows 7