WordPress RSS/Atom 提要验证,"Mismatched tag" 错误

WordPress RSS/Atom Feed Validation, "Mismatched tag" error

我们无法在 Feed Validator or the W3C Feed Validation Service.

上验证我们的 Feed

当我输入任何常见 URI 时:

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

我们正在使用自定义主题,但我无法确定是否会有干扰。我需要转义内部 HTML 还是关闭其他东西?

Cross-posted.

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

出于某种原因,functions.php 文件具有这些函数 "clean up" 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;
}

通过此修复,输出仅通过警告进行验证。