When using your main content feed to share posts via buffer or other services, it is crucial that your feed validates cleanly.
There are always things in the generated WordPress content that can break your feed validation. Here some things to cleanup or alter your delivered feed content.
is_feed()
Check for syndication request. This tag is not typically used by users; it is used internally by WordPress and is available for Plugin Developers.
Check for feed syndication in your themes functions.php
1 2 3 |
if (is_feed()) { /.. tweaks go here ../ } |
1 2 3 4 5 6 7 8 9 |
function rss_noiframe($content) { $content = preg_replace( '/<iframe(.*)\/iframe>/is', '', $content ); return $content; } add_filter('the_excerpt_rss', 'rss_noiframe'); add_filter('the_content_feed', 'rss_noiframe'); |
1 2 3 4 5 6 7 8 9 10 |
function rss_nocomments($content) { global $post; $post->comment_status="closed"; } add_filter('the_excerpt_rss', 'rss_nocomments'); add_filter('the_content_feed', 'rss_nocomments'); |
The sizes attribute breaks feed validation, here how to clean it up.
1 2 3 4 5 6 7 8 9 |
function no_responsive_image_feeds() { add_filter( 'max_srcset_image_width', function() { return 1; } ); } add_action('rss2_head', 'no_responsive_image_feeds' ); add_action('atom_head', 'no_responsive_image_feeds' ); add_action('rss_head', 'no_responsive_image_feeds' ); |
1 2 3 4 5 6 7 8 9 |
if (is_feed()) { function feedFilter($query) { if ($query->is_feed) { $query->set('post_type','any'); } return $query; } add_filter('pre_get_posts','feedFilter'); } |
1 2 3 4 5 6 7 8 9 10 11 12 |
if (is_feed()) { function feedFilter($query) { if ($query->is_feed) { $query->set('posts_per_page','11'); } return $query; } add_filter('pre_get_posts','feedFilter'); } |
1 2 3 4 5 6 7 8 9 10 |
if (is_feed()) { function feedFilter($query) { if ($query->is_feed) { $query->set('category_name', 'my-special-cat'); } return $query; } add_filter('pre_get_posts','feedFilter'); } |
I am a full-stack developer. My expertise include:
I love programming, design and know my way around server architecture as well. I would never feel complete, with one of these missing.
I have a broad range of interests, that’s why I constantly dive into new technologies and expand my knowledge where ever required. Technologies are evolving fast and I enjoy using the latest.
Apart from that, I am a peace loving guy who tries to have people around him that think the same. I truly believe in the principle: “If you help someone, someone will help you, when you need it."