WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Rewrite API/add feed

Description

Add a new feed type like /atom1/.

Requires one-time use of flush_rules() to take effect.

Usage

<?php add_feed$feedname$function ); ?> Use the init action to call this function.

Parameters

$feedname
(string) (required) Name of the feed as it will appear in the feed URL
Default: None
$function
(callback) (required) Callback to run on feed display.
Default: None

Return Values

(string) 
Feed action name.

Example

 <?php
/* Add the feed. */
function my_custom_rss_init(){
	add_feed('my_custom_feed', 'my_custom_rss');
}
add_action('init', 'my_custom_rss_init');

/* Filter the type, this hook wil set the correct HTTP header for Content-type. */
function my_custom_rss_content_type( $content_type, $type ) {
	if ( 'my_custom_feed' === $type ) {
		return feed_content_type( 'rss2' );
	}
	return $content_type;
}
add_filter( 'feed_content_type', 'my_custom_rss_content_type', 10, 2 );

/* Show the RSS Feed on domain.com/?feed=my_custom_feed or domain.com/feed/my_custom_feed. */
function my_custom_rss() {
	// Do your magic, with XML for example.
}
 ?>

Change Log

Since: 2.1

Source File

add_feed() is located in wp-includes/rewrite.php

Related

Articles

Hooks

Functions