打开Sitemap.xml时报“This page contains the following errors:”的解决方法

正文概述 云码哥   2020-11-8   5.95K

有一位朋友网站碰到了这么一个问题,准备sitemap.xml提交到百度,用的是google?xml?sitemap?插件生成,打开xml时报了错误“This page contains the following errors:”,跑来问我怎么解决,我想会不会是插件问题,后来换了Smart SEO tool,问题依旧,换其它浏览器也一样。

打开Sitemap.xml时报“This page contains the following errors:”的解决方法

后来查了度娘,说是xml文件格式错误,文件头部有空格导致的,于是我把他的sitemap.xml另存到电脑打开,确实是有两行空格:

打开Sitemap.xml时报“This page contains the following errors:”的解决方法

问题可能出在代码里面,于是找到了Smart SEO?Tool里面这段输出XML的代码:

    public static function parse_request($wp){
	    if(!isset($wp->query_vars['wb_sitemap'])){
	        return;
        }


        date_default_timezone_set(get_option('timezone_string'));
        $param = $wp->query_vars['wb_sitemap'];

	    $xml = '';
	    if(empty($param)){
            $xml = self::index();
        }else{
            $xml = self::content($param);
        }
        
        
        header('Content-Type: text/xml; charset=utf-8');
	    echo $xml;
	    exit(0);
    }

很明显是没有清空缓存造成的,加上ob_clean();后问题解决。

 

    public static function parse_request($wp){
	    if(!isset($wp->query_vars['wb_sitemap'])){
	        return;
        }


        date_default_timezone_set(get_option('timezone_string'));
        $param = $wp->query_vars['wb_sitemap'];

	    $xml = '';
	    if(empty($param)){
            $xml = self::index();
        }else{
            $xml = self::content($param);
        }
        
        ob_clean();
        header('Content-Type: text/xml; charset=utf-8');
	    echo $xml;
	    exit(0);
    }

 

 

本站大部分资源收集于网络以及网友投稿,本不保证资源的完整性以及安全性,请下载后自行测试。
本站资源仅供下载者学习技术,版权归资源原作者所有,请在下载后24小时之内自觉删除。
本站资源仅供下载者学习IT编程开发技术,请遵守国家法律法规,严禁用于非法用途。
若作商业用途,请购买正版,由于未及时购买正版发生的侵权行为,与本站无关。
如您是版权方,本站源码有侵犯到您的权益,请邮件联系331752841@qq.com 删除,我们将及时处理!

云创源码 » 打开Sitemap.xml时报“This page contains the following errors:”的解决方法

发表评论