I am trying to add a functionality to the default wordpress feed. The problem is i managed to do this modifying the rss feed php file. The problem number two that i have in mind is when wp gets an update also that file will be updated and my code will disappear.

So i am looking to for a way to insert my code as a filter or something else for the rss feed.

Note: My code does not modify the default feed content, instead i want to display another feed from external site.

add_filter( 'the_name_for_the_rss_filter', 'my_function' );

function my_function( $some_var ){ global $some_var;

if($some_var == true){

// let's say: 
// echo file_get_contents("http://example.com/feed/");
// exit(0);



2 Answers 2


You could try out the template_redirect action to overwrite the default feed template:

add_action( 'template_redirect', 'custom_template_redirect' );
function custom_template_redirect() {
    if (!is_feed()) 

    header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);

    // your own template stuff here 

  • this works only for post feed not for example.com/feed/ main feed :(
    – m3tsys
    Commented Jun 2, 2013 at 10:48
  • 1
    ok it seems to work on my install, sometimes the feed is cached in the browser, try it with a cache-busting parameter like example.com/feed/?t=1
    – birgire
    Commented Jun 2, 2013 at 11:11
  • that worked. It seems that your code is what i was looking for. Thank you for your time!
    – m3tsys
    Commented Jun 2, 2013 at 11:16
  • 1
    ok great, I added a header() example from the default rss2 template that you can modify to your needs.
    – birgire
    Commented Jun 2, 2013 at 11:40

Use fetch_feed() if you want to parse an external feed:

<?php $feed = fetch_feed( $uri ); ?>

UPDATE 1: Remove the default feeds:

remove_action('wp_head', 'feed_links_extra', 3 );
remove_action('wp_head', 'feed_links', 2 );

UPDATE 2: Add a custom feed:

add_action('wp_head', 'add_custom_feed');
function add_custom_feed() {
    echo '<link rel="alternate" type="application/rss+xml" title="Custom Feed" href="' . get_bloginfo('rss_url') . '" />'; 
  • Ok. Thank you, i will use fetch_feed but actually i don't know how to not display the default feed and display my 'fetched feed' one.
    – m3tsys
    Commented Jun 2, 2013 at 10:51
  • @m3tsys Try adding the code from my two updates to your functions.php
    – Sven
    Commented Jun 2, 2013 at 11:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.