get_feed_link

Retrieves the permalink for the feed type.

Description

(string) get_feed_link( (string) $feed = '' ); 

Returns (string)

The feed permalink.

Parameters (1)

0. $feed — Optional. (string) => ''
Feed type. Default empty.

Usage

  1. if ( !function_exists( 'get_feed_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Feed type. Default empty. 
  5. $feed = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_feed_link($feed); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/link-template.php  
  1. function get_feed_link( $feed = '' ) { 
  2. global $wp_rewrite; 
  3.  
  4. $permalink = $wp_rewrite->get_feed_permastruct(); 
  5. if ( '' != $permalink ) { 
  6. if ( false !== strpos($feed, 'comments_') ) { 
  7. $feed = str_replace('comments_', '', $feed); 
  8. $permalink = $wp_rewrite->get_comment_feed_permastruct(); 
  9.  
  10. if ( get_default_feed() == $feed ) 
  11. $feed = ''; 
  12.  
  13. $permalink = str_replace('%feed%', $feed, $permalink); 
  14. $permalink = preg_replace('#/+#', '/', "/$permalink"); 
  15. $output = home_url( user_trailingslashit($permalink, 'feed') ); 
  16. } else { 
  17. if ( empty($feed) ) 
  18. $feed = get_default_feed(); 
  19.  
  20. if ( false !== strpos($feed, 'comments_') ) 
  21. $feed = str_replace('comments_', 'comments-', $feed); 
  22.  
  23. $output = home_url("?feed={$feed}"); 
  24.  
  25. /** 
  26. * Filters the feed type permalink. 
  27. * @since 1.5.0 
  28. * @param string $output The feed permalink. 
  29. * @param string $feed Feed type. 
  30. */ 
  31. return apply_filters( 'feed_link', $output, $feed );