1

My WordPress 4.2.2 generates a post feed with this

<content:encoded><![CDATA[
<p>
...some html here...
<iframe style="border: 1px solid #CCC; border-width: 1px; margin-bottom: 5px; max-width: 100%;" src="//an_external_url" width="425" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen="allowfullscreen"> </iframe>
</p>
]]></content:encoded>

but when I validate this feed with https://validator.w3.org/feed/, it throws an error:

line xx, column 0: content:encoded should not contain iframe tag

Here is the $content being echoed within CDATA at /wp-includes/feed-rss2.php:

<?php $content = get_the_content_feed('rss2'); ?>
<?php if ( strlen( $content ) > 0 ) : ?>
    <content:encoded><![CDATA[<?php echo $content; ?>]]></content:encoded>

My question is if WordPress get_the_content_feed strips or not any invalid tags or html entities such as &nbsp;. If this function is being used, it seems str_replace is not enough.

What could I do to make WordPress generate valid feeds?

Here is the latest source code:

181 function get_the_content_feed($feed_type = null) {
182         if ( !$feed_type )
183                 $feed_type = get_default_feed();
184 
185         /** This filter is documented in wp-includes/post-template.php */
186         $content = apply_filters( 'the_content', get_the_content() );
187         $content = str_replace(']]>', ']]&gt;', $content);
188         /**
189          * Filter the post content for use in feeds.
190          *
191          * @since 2.9.0
192          *
193          * @param string $content   The current post content.
194          * @param string $feed_type Type of feed. Possible values include 'rss2', 'atom'.
195          *                          Default 'rss2'.
196          */
197         return apply_filters( 'the_content_feed', $content, $feed_type );
198 }
1
  • get_the_content_feed()'s return value is in (string) format, but I am not sure if it strip the html, or just sanitize it. Also htmlspecialchars() seems like a better option for the bonus filtering. – knif3r Jul 18 '16 at 9:09

Your Answer

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

Browse other questions tagged or ask your own question.