get_feed_link() WordPress Function

The get_feed_link() function in WordPress allows you to retrieve the link for the RSS feed of the current site. This function can be useful if you want to display the RSS feed link on your site or create a custom RSS feed for your site.

get_feed_link( string $feed = '' ) #

Retrieves the permalink for the feed type.


Parameters

$feed

(string)(Optional) Feed type. Possible values include 'rss2', 'atom'. Default is the value of get_default_feed().

Default value: ''


Top ↑

Return

(string) The feed permalink.


Top ↑

Source

File: wp-includes/link-template.php

function get_feed_link( $feed = '' ) {
	global $wp_rewrite;

	$permalink = $wp_rewrite->get_feed_permastruct();

	if ( $permalink ) {
		if ( false !== strpos( $feed, 'comments_' ) ) {
			$feed      = str_replace( 'comments_', '', $feed );
			$permalink = $wp_rewrite->get_comment_feed_permastruct();
		}

		if ( get_default_feed() == $feed ) {
			$feed = '';
		}

		$permalink = str_replace( '%feed%', $feed, $permalink );
		$permalink = preg_replace( '#/+#', '/', "/$permalink" );
		$output    = home_url( user_trailingslashit( $permalink, 'feed' ) );
	} else {
		if ( empty( $feed ) ) {
			$feed = get_default_feed();
		}

		if ( false !== strpos( $feed, 'comments_' ) ) {
			$feed = str_replace( 'comments_', 'comments-', $feed );
		}

		$output = home_url( "?feed={$feed}" );
	}

	/**
	 * Filters the feed type permalink.
	 *
	 * @since 1.5.0
	 *
	 * @param string $output The feed permalink.
	 * @param string $feed   The feed type. Possible values include 'rss2', 'atom',
	 *                       or an empty string for the default feed type.
	 */
	return apply_filters( 'feed_link', $output, $feed );
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.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.

Show More
Show More