Skip to content

March 4, 2011

2

Modified RSS Feed URL in WordPress

Load time on my wordpress blog has become a small problem. I have been recommended by many people to turn off all of my plugins and only use the ones I really needed so there was no bottle neck in my php code. My progress has included hard coding 4 plugins so the code will hopefully run smoother and a little quicker. I have run into one plugin that I could not hard code. I wanted to change the default URL for the blogs RSS feed. I have a feedburner account and wanted to link direct. After many failed attempts to code a different url for my rss feed, I turned to twitter. A suggestion comes in from Jon Bishop and he shared his own code.

<?php
// To rewrite the feed links
add_filter('feed_link', 'my_feedburner_feed_link', 1, 2);
// To redirect feeds
add_action('template_redirect', 'my_feed_redirect');
 
function my_feed_redirect() {
    global $feed;
    // Change this
    $new_feed = 'http://www.mynewfeed.com';
 
    if (!is_feed()) {
            return;
    }
    if (preg_match('/feedburner/i', $_SERVER['HTTP_USER_AGENT'])){
            return;
    }
 
    if ($feed != 'comments-rss2') {
            if (function_exists('status_header')) status_header( 302 );
            header("Location:" . $new_feed);
            header("HTTP/1.1 302 Temporary Redirect");
            exit();
    }
}
 
function my_feedburner_feed_link($output, $feed){
    // Change this
    $new_feed = 'http://www.mynewfeed.com';
 
    if($feed!='comments-rss2'){
            $feed_array = array('rss' =&gt; $new_feed , 'rss2' =&gt; $new_feed , 'atom' =&gt; $new_feed , 'rdf' =&gt; $new_feed , 'comments_rss2' =&gt; '');
            $feed_array[$feed] = $new_feed ;
            $output = $feed_array[$feed];
    }
    return $output;
}
?>

This code should be placed in your function.php file. There are two placing in the code where you need to enter your specific feed url. If you are running a parent/child theme, pull over a copy from the parent folder to the child folder. This will save you from changing it later when your parent theme is upgraded. It has worked without any trouble. OriginalĀ Code is also available onĀ Pastie.

2 Comments Post a comment
  1. Jan 8 2014

    It’s awesome to visit this web site and reading the views of all mates concerning this
    post, while I am also eager of getting familiarity.

    Reply

Trackbacks & Pingbacks

  1. Redirect your RSS Feed Without Plugins or Editing htaccess [WORDPRESS]

Leave a comment

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments

required
required