【问题标题】:WordPress RSS/Atom Feed Validation, "Mismatched tag" errorWordPress RSS/Atom 提要验证,“标签不匹配”错误
【发布时间】:2016-02-15 14:41:54
【问题描述】:

我们无法在 Feed ValidatorW3C Feed Validation Service 上验证我们的提要。

当我输入任何常见的 URI 时:

  • [网站网址]/feed
  • [siteurl]/feed/atom
  • [siteurl]/feed/rss2

我收到与标签不匹配有关的各种错误,通常是文档末尾的 </channel> 结束标签,或者帖子末尾的 </entry> 标签。

我们使用的是自定义主题,但我不知道是否会有干扰。我是否需要转义内部 HTML 或关闭其他内容?

Cross-posted.

【问题讨论】:

    标签: php xml wordpress validation feed


    【解决方案1】:

    仔细检查输出后,所有没有显式结束标记的元素都缺少自结束符号,即<content ... />;

    由于某种原因,functions.php 文件具有这些功能来“清理”HTML5 的输出:

    /**********************************************
    REMOVE SELF-CLOSING TAGS && USER-HARDCODED TAGS
    ***********************************************/
    
    if ( !is_admin() && ( ! defined('DOING_AJAX') || ( defined('DOING_AJAX') && ! DOING_AJAX ) ) ) {
        ob_start( 'html5_slash_fixer' );
        add_action( 'shutdown', 'html5_slash_fixer_flush' );
    }
    
    function html5_slash_fixer( $buffer ) {
        $buffer = str_replace( '<p id="top" />', null, $buffer );
        $buffer = str_replace( ' />', '>', $buffer );
        return $buffer;
    }
    
    function html5_slash_fixer_flush() {
        ob_end_flush();
    }
    

    所以我在html5_slash_fixer_flush 方法中添加了一个检查,以确定当前查询是否针对提要:is_feed (WordPress Codex)

    function html5_slash_fixer( $buffer ) {
        $buffer = str_replace( '<p id="top" />', null, $buffer );
        if( !is_feed() ){
            $buffer = str_replace( ' />', '>', $buffer );
        }
        return $buffer;
    }
    

    使用此修复程序,输出验证仅包含警告。

    【讨论】:

      猜你喜欢
      • 2010-12-19
      • 1970-01-01
      • 2020-07-24
      • 2010-10-01
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      相关资源
      最近更新 更多