Adding Custom Post Type to Default RSS Feed

Ever since WordPress 3.0 rolled out, Custom Post Type was one of the most talked about topic. CPT definitely paved the way for web designers and developers to expand their horizon and take WordPress little more seriously. Making WordPress from a simple blog site manager to a full fledged web CMS.

However, like regular blog posts, CPT posts doesn’t show up on your default RSS feed url. Default RSS feed of your site (for posts) should be:

https://www.yourdomain.com/feed

On the other hand, default CPT RSS feed url can found from:

https://www.yourdomain.com/feed/?post_type=CPT

Here “CPT” would replace with your registered CPT type. It would vary depending on how you have registered your CPT type. This could be a bit confusing for users unless you add direct link of your CPT type on your site.

But there is a way to add all of your CPT posts on your default RSS feed. Simply place the following snippet on your current theme’s functions.php file and save it.

<?php
function cpt_on_feed($qv) {
   if (isset($qv['feed']) && !isset($qv['post_type']))
     $qv['post_type'] = array('post','CPT');
     return $qv; }
add_filter('request','cpt_on_feed');
?>

Check your default RSS feed after adding few more posts on your CPT type.

Source: WP Discussion.

Today In History

  •  
  •  

Comment

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from Postable, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.