add_feed() WordPress Function

The add_feed() function enables you to add a custom RSS feed to your WordPress site. This function takes two arguments: the first is the feed URL, and the second is an optional array of parameters.

add_feed( string $feedname, callable $function ) #

Adds a new feed type like /atom1/.


Parameters

$feedname

(string)(Required)Feed name.

$function

(callable)(Required)Callback to run on feed display.


Top ↑

Return

(string) Feed action name.


Top ↑

More Information

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


Top ↑

Source

File: wp-includes/rewrite.php

function add_feed( $feedname, $function ) {
	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, $function, 10, 2 );

	return $hook;
}


Top ↑

Changelog

Changelog
VersionDescription
2.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.