0

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:

  • [siteurl]/feed
  • [siteurl]/feed/atom
  • [siteurl]/feed/rss2

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?

1
  • Have you tried with the default theme and without plugins? Also what exactly is not validating? The content or the surroundings?
    – kaiser
    Feb 29 '16 at 15:19
1

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 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.