InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress RSS feed tutorials

  • create rss feed for wordpress on Google feedburner
  • use your own domain name for feedburner feed
  • redirect wordpress feed to feedburner feed
  • setup Google feedburner email subscription newsletter
  • Google feedburner email subscription vs Mailchimp
  • setup MailChimp Rss email campaign
  • ping feedburner to force update rss cache
  • customize wordpress rss feed
  • Fetch wordpress rss feed as FeedBurner user agent
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress RSS feed

How to customize wordpress rss feed

By admin on Nov 19, 2015

By defaul WordPress will include all posts sorted by creation time for rss feed. If you want to customize wordpress feed, you can write custom code to include wordpress pages, skip specific entries, etc. Here are steps to customize wordpress feed for few cases:

Include pages in wordpress feed

To incluse wordpress pages to feed, we can use pre_get_posts hook as shown below:

function pre_get_posts_rss ($query) {
  if (is_feed() ) {
    $query->set('post_type', array('post', 'page'));
  }
}
add_action('pre_get_posts', 'pre_get_posts_rss');

Change posts per rss wordpress feed

To change posts per rss, we can add filter to pre_option_posts_per_rss and set the desired value as shown below:

add_filter('pre_option_posts_per_rss', function() { return 30;});

Skip certain posts based on meta key

In case you want to skip some post based on meta key or other custom logic, you can attach hook to posts_results. In the following code we’ll skip post which have meta key skip_rss. We’ll also skip non-leaf pages.

function posts_results_rss( $posts ) {
  if (!is_feed() ) {
    return $posts;
  }
  $filtered_posts = array();
  foreach ( $posts as $post ) {
    $skip_rss = get_post_meta($post->ID, 'skip_rss', true);
    $is_leaf = _is_leaf_page($post->ID);
    if (!$skip_rss && $is_leaf) {
      $filtered_posts[] = $post;
    }
    if (count($filtered_posts) >= 10) {
      break;
    }
  }
  return $filtered_posts ;
}
add_filter( 'posts_results', 'posts_results_rss' );

Note that for this logic to work properly, you need to increase posts per rss so that we get enough entries in function posts_results_rss. Implementation for function _is_leaf_page can see seen in article Find if a wordpress is leaf.

Suggested posts:

  1. How to display wordpress top level pages
  2. Svn – how to view older version of a file
  3. Fetch wordpress rss feed as FeedBurner user agent on command line
  4. How to create Linux instance on Amazon AWS/EC2 Classic
  5. How to use your own domain name for feedburner feed urls
  6. How to restrict dropbox network bandwith on Mac
  7. How to setup wordpress custom query params with pretty url format
  8. How to add tag and category to wordpress pages
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, Tutorials, Ubuntu Linux, Web Development, Wordpress, Wordpress RSS feed
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress