get_feed_link( string $feed = '' ): string
- Since
- 1.5.0
- Source
wp-includes/link-template.php:693
Retrieves the permalink for the feed type.
Parameters
$feedstringoptional- Feed type. Possible values include 'rss2', 'atom'. Default is the value of get_default_feed().Default:
''
Return
string- The feed permalink.
Hooks fired · 1
One hook fires while get_feed_link() runs, in this order:
Uses · 5
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- get_default_feed()Retrieves the default feed.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- user_trailingslashit()Retrieves a trailing-slashed string if the site is set for adding trailing slashes.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 4
- feed_links()Displays the links to the general feeds.
- get_bloginfo()Retrieves information about the current site.
- redirect_canonical()Redirects incoming links to the proper URL based on the site url.
- the_feed_link()Displays the permalink for the feed type.
Source
function get_feed_link( $feed = '' ) { global $wp_rewrite; $permalink = $wp_rewrite->get_feed_permastruct(); if ( $permalink ) { if ( str_contains( $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 ( str_contains( $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 );}History
Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/link-template.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.