• How To?
  • Tips ‘n Tricks
  • WordPress
  • Snippets
  • Software
    • Browsers
    • Downloads
  • Web
  • Tools
    • Character Counter
    • chmod Calculator
    • Entities Encoder
    • Live HTML Editor
    • My IP
  • Contact
Twitter Facebook Google+ RSS
You are here: SumTips » Snippets » WordPress Snippets » Add Pages, Custom Post Types in WordPress Site Feed

Add Pages, Custom Post Types in WordPress Site Feed

Posted on December 26, 2011 by Renji | Short URL: http://sumtips.com/?p=6132

If you are running your WordPress site as a CMS, you may come across need to include pages from your site in the main feed, along with your posts. Well, the below code will give you that ability.

function add_pages_to_rss_feed( $args ) {
  if ( isset( $args['feed'] ) && !isset( $args['post_type'] ) )
    $args['post_type'] = array('post', 'page');
  return $args;
}

add_filter( 'request', 'add_pages_to_rss_feed' );

All it is doing is to include the post type ‘Page’  in the feed.

I have created a plugin that does the above. If you don’t want to manually edit any code, install Pages and Posts in Feed plugin.

So, if you’d like to include additional custom post types in feed, you can do that by including them in the arguments array like this:

    $args['post_type'] = array('post', 'page', 'movies', 'songs');

And finally, if you don’t want any blog posts to show up in the feed, simply remove post type ‘Post’ from the argument. That would look something like this:

    $args['post_type'] = array('page', 'movies', 'songs');

With this code in your default theme’s functions.php file, all “Post” items would be excluded from the feed.

Similar to earlier plugin, if you want only pages in your feed, get Only Pages in Feed plugin.

With the code in place, the number of items in feed is still controlled from ‘Reading Settings’ in WordPress dashboard.


Tweet

Related posts:

  • Exclude Specific Post, Category and Author from WordPress Feed
  • Change "Enter title here" text for Post, Page and Custom Post Type in WordPress
  • Set Different Post Templates Based on ID, Tag and Category in WordPress
  • Convert Partial Feed into Full Feed with WizardRSS
  • Get Color-Coded Post Statuses in WordPress with UI Labs
Categories: WordPress Snippets
Automatically Add Attributes to All Images in WordPress Posts
Convert WordPress Tables from InnoDB to MyISAM, and vice-versa

4 Responses to “Add Pages, Custom Post Types in WordPress Site Feed”

  1. DRG says:
    December 27, 2011 at 9:54 AM

    Thanks for the info..!!!

  2. David E says:
    January 16, 2012 at 4:52 AM

    Hi: Renji:

    I am interest to allow the feed to point to certain page to publish their updated items from recent ly updated pages (no post). Will your Add Pages, Custom Post Types in WordPress Site Feed
    Plugin do this or addition programming is involve? If not, can your include this in next version. I wish to have a pick list to enable certain page feeds on a page (Home page).

    Thanks
    David

  3. Pages and Posts in Feed | Best Plugins - wordpress – widgets – plugin 2012 says:
    June 10, 2012 at 12:46 AM

    [...] SumTips (http://sumtips.com/wp-page-in-feed) [...]

  4. Only Pages in Feed | Best Plugins - wordpress – widgets – plugin 2012 says:
    June 10, 2012 at 2:10 AM

    [...] SumTips (http://sumtips.com/wp-page-in-feed) [...]

  • Get Updates via Email

  • Recent Posts

    • CMS2CMS: Migrate Site from Drupal or Joomla to WordPress
    • WordPress: Add Preview Button in Distraction Free Writing
    • How to Activate or Deactivate Individual Jetpack Modules
    • Windows 8: Auto Update Defender with Windows Update Disabled
    • Automatically Start and Close Programs at Specific Time
    • How to Copy Code from Notepad++ with Syntax Highlighting
  • Random Posts

    • Free Services to Upload & Embed MP3 Music Player on Your Site
    • Download Videos Without Using Extensions
    • Get Unread Gmail Message Count in Favicon
    • Upload Files to Multiple File Hosting Services
    • Download Opera Mini 5.1 for Android, Symbian, Windows Mobile, Blackberry and Java
    • How to Customize Windows 8 Logon Screen Background Color
  • Categories

    • Blogging
    • Games
    • Google
    • How To?
    • Linux
    • Microsoft
      • Windows
    • Miscellaneous
    • Phone
    • Snippets
      • AutoHotkey Snippets
      • CSS Snippets
      • htaccess Snippets
      • JavaScript Snippets
      • PowerShell Snippets
      • WordPress Snippets
    • Social
    • Software
      • Browsers
    • Tips 'n Tricks
    • Wallpapers
    • Web
© SumTips. Contact | Sitemap | Privacy Policy