We are having trouble getting our feeds to validate on either Feed Validator or the W3C Feed Validation Service.
When I enter any of the common URI's:
I get various errors related to mismatched tags, usually either the </channel>
closing tag at the end of the document, or the </entry>
tag at the end of a post.
We are using a custom theme, but I can't tell if something there would be interfering. Do I need to escape the inner HTML or close something else?
Upon closer examination of the output, all of the elements that did not have explicit closing tags were missing the self-closing notation i.e. <content ... />
;
For some reason the functions.php
file had these functions to "clean up" the output for 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();
}
So I added a check in the html5_slash_fixer_flush
method to determine if the current query is for a feed: 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;
}
With this fix, the output validates with warnings only.