Support » Fixing WordPress » trying to rewrite custom rss feed URL

  • Resolved bigcityjohn


    I’ve created a new custom rss feed file (mycustomfeed.php) which is accessible at I’ve searched the forums for help trying to rewrite the URL, and found a link to the following bit of code from

    This piece of code will allow you to have any feed name, and dynamically “create” /customfeed.xml as well as a /feed/customfeed/ versions:

    function custom_feed_rewrite($wp_rewrite) {
    $feed_rules = array(
    'feed/(.+)' => 'index.php?feed=' . $wp_rewrite->preg_index(1),
    '(.+).xml' => 'index.php?feed='. $wp_rewrite->preg_index(1)
    $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
    add_filter('generate_rewrite_rules', 'custom_feed_rewrite');

    So, I added the code to my functions.php file, but I’m not having any luck accessing the feed at or

    Is there something incorrect in the bit of code that I copied, or am I missing something in the code that I need to customize? Or, perhaps, is there a better/easier way for me to do a rewrite so that I can access my custom feed at /mycustomfeed.xml and/or /feed/mycustomfeed ?

Viewing 6 replies - 1 through 6 (of 6 total)
  • This works for me

    add_action('init', 'my_add_feed');
    function my_rewrite_rules( $wp_rewrite ) {
      $new_rules = array(
        'feed/(.+)' => 'index.php?feed='.$wp_rewrite->preg_index(1)
      $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
    function my_add_feed(  ) {
      global $wp_rewrite;
      add_feed('custom-feed', 'my_create_feed');
      add_action('generate_rewrite_rules', 'my_rewrite_rules');

    where /feed/custom-feed/ would be the “pretty” permalink

    I should add that my_create_feed is the function that actually, well, creates the feed content.

    Thanks, miklb! This works perfectly for the rewrite. I appreciate the help…would’ve never figured this out on my own.

    I want to take this RSS feed , or something like it,
    and recreate it using the zipcode from the user profile field %field_9 field_zip-code alt”%

    But, I can’t get it to work. I want the weather to show up in a bottom widget area unique to the users zipcode field from their profile in Buddypress.

    Anyone know how I can do this?

    I think it is failing to pull the user’s zipcode field setting because the RSS feed is from and not my domain.

    Any ideas?

    Tony, my issue here is marked “Resolved.” You’ll need to start a new thread for your own, unique issue.

    @tony Locke: stop posting the same question all over the place! Stick to your own topic.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘trying to rewrite custom rss feed URL’ is closed to new replies.