Cleaning up the WordPress Feed (Validation)

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.

CONDITIONAL TAGS

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. if (is_feed()) {
  2.     /.. tweaks go here ../
  3. }

REMOVE IFRAMES

  1. function rss_noiframe($content) {
  2.        
  3.     $content = preg_replace( '/<iframe(.*)\/iframe>/is', '', $content );
  4.  
  5.     return $content;
  6. }
  7.  
  8. add_filter('the_excerpt_rss', 'rss_noiframe');
  9. add_filter('the_content_feed', 'rss_noiframe');

REMOVE / DISABLE COMMENTS

  1. function rss_nocomments($content) {
  2.    
  3.      global $post;
  4.       $post->comment_status="closed";
  5.    
  6.  
  7. }
  8.  
  9. add_filter('the_excerpt_rss', 'rss_nocomments');
  10. add_filter('the_content_feed', 'rss_nocomments');

REMOVE RESPONSIVE IMAGES

The sizes attribute breaks feed validation, here how to clean it up.

  1. function no_responsive_image_feeds() {
  2.     add_filter( 'max_srcset_image_width', function() {
  3.        return 1;
  4.     } );
  5. }
  6.  
  7. add_action('rss2_head', 'no_responsive_image_feeds' );
  8. add_action('atom_head', 'no_responsive_image_feeds' );
  9. add_action('rss_head', 'no_responsive_image_feeds' );

INCLUDE PAGES IN POST FEED

  1. if (is_feed()) {
  2. function feedFilter($query) {
  3.         if ($query->is_feed) {
  4.                 $query->set('post_type','any');
  5.                 }
  6.         return $query;
  7. }
  8. add_filter('pre_get_posts','feedFilter');
  9. }

ADJUST AMOUNT OF POSTS

  1. if (is_feed()) {
  2.  
  3. function feedFilter($query) {
  4.         if ($query->is_feed) {
  5.                 $query->set('posts_per_page','11');
  6.         }
  7.  
  8.         return $query;
  9. }
  10. add_filter('pre_get_posts','feedFilter');
  11.  
  12. }

LIMIT BY CATEGORY

  1. if (is_feed()) {
  2. function feedFilter($query) {
  3.         if ($query->is_feed) {
  4.                 $query->set('category_name', 'my-special-cat');
  5.         }
  6.  
  7.         return $query;
  8. }
  9. add_filter('pre_get_posts','feedFilter');
  10. }

 

Enjoy coding …

Alex

I am a full-stack developer. 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."

Recent Posts

Particle Network Animations in Javascript

What are particle animations? Particle network animations in JavaScript typically involve creating visual representations of… Read More

2 days ago

B&B / Hotel Booking Solutions for WordPress | 2024

BOOKING SOLUTIONS 202x This is my take on a subset of booking, appointment, PMS or… Read More

1 month ago

WordPress Cron + WP-CLI + Ntfy

THE GOAL Create a system cron for WordPress, that is accessible and can be easily… Read More

2 months ago

2024 is here and now :)

2024, what's cooking? Slowly getting into the 2024 spirit. 3 projects coming to a close… Read More

4 months ago

2023 ends and whats next !

Short look back at 2023 This has been a busy and interesting year. I am… Read More

4 months ago

cubicFUSION Grid Tweaker – Elementor Grid made easy.

Elementor Pro provides grid containers as an experimental feature. The options provided are limited, when… Read More

5 months ago