Title: Using 2 modified feed templates.
Last modified: September 2, 2016

---

# Using 2 modified feed templates.

 *  [gulliver](https://wordpress.org/support/users/gulliver/)
 * (@gulliver)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/using-2-modified-feed-templates/)
 * I’ve been using an added function to load a modified rss template. Works fine,
   but now I need to add a custom template for a CPT.
 * I have code for each,which works ok, but can’t be used together because one over-
   rides the other.
 * I don’t know enough php to modify.
 * Here’s the code I’m using…
 *     ```
       remove_all_actions( 'do_feed_rss2' );
       add_action( 'do_feed_rss2', function() {
       if ( $rss_template = locate_template( '/feeds/notes-feed.php' ) )
       load_template( $rss_template );
       else
       do_feed_rss2(); // Call default function
       }, 10, 1 );
       ```
   
 * and
 *     ```
       remove_all_actions( 'do_feed_rss2' );
       add_action( 'do_feed_rss2', 'item_feed_rss2', 10, 1 );
       function item_feed_rss2() {
       $rss_template = get_template_directory() . '/feeds/item-feed.php';
       if( get_query_var( 'post_type' ) == 'item' and file_exists(      $rss_template ) )
       load_template( $rss_template );
       else
       do_feed_rss2(); // Call default function
       ```
   
    -  This topic was modified 9 years, 9 months ago by [gulliver](https://wordpress.org/support/users/gulliver/).

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [gulliver](https://wordpress.org/support/users/gulliver/)
 * (@gulliver)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/using-2-modified-feed-templates/#post-8133380)
 * UPDATE…
 * With relatively little php knowledge, I’m wondering if I can use this…
 *     ```
       remove_all_actions( 'do_feed_rss2' );
       add_action( 'do_feed_rss2', 'item_feed_rss2', 10, 1 );
       function item_feed_rss2() {
       $rss_template = get_template_directory() . '/feeds/item-feed.php';
       $rss_template_notes = get_template_directory() . '/feeds/notes-feed.php';
       if( get_query_var( 'post_type' ) == 'item' and file_exists( $rss_template ) )
       load_template( $rss_template );
       elseif( get_query_var( 'post' ) and file_exists( $rss_template_notes ) )
       load_template( $rss_template_notes );
       else
       do_feed_rss2(); // Call default function
       }
       ```
   
 *  Thread Starter [gulliver](https://wordpress.org/support/users/gulliver/)
 * (@gulliver)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/using-2-modified-feed-templates/#post-8149436)
 * FURTHER UPDATE…
 * I’ll add this in case it’s of use to someone.
 * It seems to work ok with…
 *     ```
       // This delivers valid feeds, with the correct templates.
       remove_all_actions( 'do_feed_rss2' );
       add_action( 'do_feed_rss2', function() {
       $rss_template = get_template_directory() . '/feeds/item-feed.php';
       $rss_template2 = get_template_directory() . '/feeds/notes-feed.php';
       //if ( $post_type = 'item'  )
       if( get_query_var( 'post_type' ) == 'item' and file_exists( $rss_template ) )
       load_template($rss_template);
       elseif ( $post_type = 'post' )
       load_template($rss_template2);
       else
       do_feed_rss2(); // Call default function
       }, 10, 1 );
       ```
   
 * This enables use of a custom template for the feed of normal posts, and use of
   a different custom template for the feed of the CPT ‘item’.
 * The feeds differ in channel title/link/description.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Using 2 modified feed templates.’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 1 participant
 * Last reply from: [gulliver](https://wordpress.org/support/users/gulliver/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/using-2-modified-feed-templates/#post-8149436)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
