On this page
get_feed_link( string $feed = '' ): string
Retrieves the permalink for the feed type.
Parameters
$feedstring Optional-
Feed type. Possible values include
'rss2','atom'.
Default is the value of get_default_feed() .Default:
''
Return
string The feed permalink.
Source
File: wp-includes/link-template.php. View all references
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 );
}
Hooks
- apply_filters( 'feed_link',
string $output ,string $feed ) -
Filters the feed type permalink.
Related
Uses
| Uses | Description |
|---|---|
| user_trailingslashit() wp-includes/link-template.php | Retrieves a trailing-slashed string if the site is set for adding trailing slashes. |
| get_default_feed() wp-includes/feed.php | Retrieves the default feed. |
| WP_Rewrite::get_feed_permastruct() wp-includes/class-wp-rewrite.php | Retrieves the feed permalink structure. |
| WP_Rewrite::get_comment_feed_permastruct() wp-includes/class-wp-rewrite.php | Retrieves the comment feed permalink structure. |
| home_url() wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| feed_links() wp-includes/general-template.php | Displays the links to the general feeds. |
| get_bloginfo() wp-includes/general-template.php | Retrieves information about the current site. |
| the_feed_link() wp-includes/link-template.php | Displays the permalink for the feed type. |
| redirect_canonical() wp-includes/canonical.php | Redirects incoming links to the proper URL based on the site url. |
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_feed_link