Title: add_feed
Published: April 25, 2014
Last modified: February 24, 2026

---

# add_feed( string $feedname, callable $callback ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#return)
 * [More Information](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#wp--skip-link--target)

Adds a new feed type like /atom1/.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#parameters)󠁿

 `$feedname`stringrequired

Feed name. Should not start with `'_'`.

`$callback`callablerequired

Callback to run on feed display.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#return)󠁿

 string Feed action name.

## 󠀁[More Information](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#more-information)󠁿

Requires one-time use of [flush_rules()](https://developer.wordpress.org/reference/classes/wp_rewrite/flush_rules/)
to take effect.

`$feedname` parameter should not start with ‘`_`‘. Please refer [#59945](https://core.trac.wordpress.org/ticket/59945).

## 󠀁[Source](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#source)󠁿

    ```php
    function add_feed( $feedname, $callback ) {
    	global $wp_rewrite;

    	if ( ! in_array( $feedname, $wp_rewrite->feeds, true ) ) {
    		$wp_rewrite->feeds[] = $feedname;
    	}

    	$hook = 'do_feed_' . $feedname;

    	// Remove default function hook.
    	remove_action( $hook, $hook );

    	add_action( $hook, $callback, 10, 2 );

    	return $hook;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rewrite.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rewrite.php#L251)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rewrite.php#L251-L266)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#related)󠁿

| Uses | Description | 
| [remove_action()](https://developer.wordpress.org/reference/functions/remove_action/)`wp-includes/plugin.php` |

Removes a callback function from an action hook.

  | 
| [add_action()](https://developer.wordpress.org/reference/functions/add_action/)`wp-includes/plugin.php` |

Adds a callback function to an action hook.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.1.0](https://developer.wordpress.org/reference/since/2.1.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 5 content](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#comment-content-2086)
 2.    [Steven Word](https://profiles.wordpress.org/stevenkword/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/add_feed/#comment-2086)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%23comment-2086)
     Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%23comment-2086)
 4.  When a new custom feed is added, the endpoint will render using a `Content-Type:
     application/octet-stream; charset=UTF-8` by default. It would be useful to document
     working with content types in combination with [add_feed()](https://developer.wordpress.org/reference/functions/add_feed/).
 5.  For example either:
 6.      ```php
         function add_custom_feed() {
         	add_feed( 'custom', 'render_custom_feed' );
         }
         add_action( 'init', 'add_custom_feed' );
     
         function render_custom_feed() {
         	header( 'Content-Type: application/rss+xml' );
         	echo 'aye!';
         }
         ```
     
 7.  or:
 8.      ```php
         function add_custom_feed() {
         	add_feed( 'custom', 'render_custom_feed' );
         }
         add_action( 'init', 'add_custom_feed' );
     
     
         function custom_feed_content_type( $content_type, $type ) {
         	if( 'custom' == $type ) {
         		$content_type = 'application/rss+xml';
         	}
         	return $content_type;
         }
         add_filter( 'feed_content_type', 'custom_feed_content_type', 10, 2 );
     
         function render_custom_feed() {
         	echo 'aye!';
         }
         ```
     
 9.  will work.
 10. See: [https://core.trac.wordpress.org/ticket/36334](https://core.trac.wordpress.org/ticket/36334)
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%3Freplytocom%3D2086%23feedback-editor-2086)
 12.  [Skip to note 6 content](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#comment-content-3905)
 13.   [MakeWebBetter](https://profiles.wordpress.org/makewebbetter/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/add_feed/#comment-3905)
 14. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%23comment-3905)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%23comment-3905)
 15. **Usage of [add_feed()](https://developer.wordpress.org/reference/functions/add_feed/)**
 16.     ```php
         function wpdocs_add_mwb_feed() {
             add_feed( 'mwbfeed', 'wpdocs_makewebbetter_feed' );
         }
         add_action( 'init', 'wpdocs_add_mwb_feed' );
     
         function wpdocs_makewebbetter_feed() {
             add_filter( 'pre_option_rss_use_excerpt', '__return_zero' );
             load_template( PATHTEMPLATEFILE . '/feeds/a-feed-template.php' );
         }
         ```
     
 17.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%3Freplytocom%3D3905%23feedback-editor-3905)
 18.  [Skip to note 7 content](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#comment-content-4237)
 19.   [M.Code](https://profiles.wordpress.org/devloper00/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/add_feed/#comment-4237)
 20. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%23comment-4237)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%23comment-4237)
 21. **RSS Feed based on custom WP Query with parameters**
 22.     ```php
         add_action( 'init', 'wpdocs_custom_feed_rss2' );
         function wpdocs_custom_feed_rss2() {
     
             // Create your feed name like this : https://yoursite.com/wpdocs_custom?tag=test
             add_feed( 'wpdocs_custom', 'wpdocs_change_main_query' );
             function wpdocs_change_main_query() {
     
                 // Set right headers for RSS Feed
                 header( 'Content-Type: application/rss+xml' );
     
                 // Get main WP Query
                 global $wp_query;
     
                 // Get parameters in url
                 if ( ! empty( $_GET['tag'] ) ) :
                     $tag = $_GET['tag'];
                 endif;
     
                 // Overwrite main WP Query with yours
                 $wp_query = new WP_Query(
                     array(
                         'post_type' => 'any',
                         'fields'    => 'ids',
                         'tag'       => $tag,
                     )
                 );
     
                 // Use the basic template to load your custom RSS Feed
                 get_template_part( 'feed', 'rss2' );
             }
         }
         ```
     
 23.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%3Freplytocom%3D4237%23feedback-editor-4237)
 24.  [Skip to note 8 content](https://developer.wordpress.org/reference/functions/add_feed/?output_format=md#comment-content-7071)
 25.   [Narendra Sishodiya](https://profiles.wordpress.org/narenin/)  [  2 years ago  ](https://developer.wordpress.org/reference/functions/add_feed/#comment-7071)
 26. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%23comment-7071)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%23comment-7071)
 27. The **Feed name Parameters $feedname**(required) should not start with **`_`**
     if it start with this then we will recieve the **wp_die** error message.
 28.     ```php
         function feed2_callback( $is_comment_feed, $feed ) {
         	header( 'Content-Type: application/xml; charset=UTF-8', true );
         	echo '';
         ?>
     
         	Test
     
         <?php
         }
     
         add_feed( '_feed2', 'feed2_callback' );
         ```
     
 29. Next, update the rewrite rule and access [http://localhost/_feed2](http://localhost/_feed2),
     which will return **wp_die** with **404** status.
 30. This is not a problem with the code I tried, but because the “_” at the beginning
     of the feed name is removed in the do_feed function.
 31.     ```php
         function do_feed() {
         	global $wp_query;
     
         	$feed = get_query_var( 'feed' );
     
         	// Remove the pad, if present.
         	$feed = preg_replace( '/^_+/', '', $feed );
         ```
     
 32. This process results in an action name of `'do_feed_' . 'feed2'` when `$feed` 
     is `'_feed2'`.
 33. Since this is not done in the `add_feed` function and the action name specified
     in the `add_action` function is `'do_feed_' . '_feed2'`, since the two action 
     names do not match, which resulting in the error indicated in the response.
 34.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F%3Freplytocom%3D7071%23feedback-editor-7071)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fadd_feed%2F)
before being able to contribute a note or feedback.