get_post_comments_feed_link

Retrieves the permalink for the post comments feed.

Description

(string) get_post_comments_feed_link( (int) $post_id = 0, (string) $feed = '' ); 

Returns (string)

The permalink for the comments feed for the given post.

Parameters (2)

0. $post_id — Optional. (int)
Post ID. Default is the ID of the global $post..
1. $feed — Optional. (string) => ''
Feed type. Default empty.

Usage

  1. if ( !function_exists( 'get_post_comments_feed_link' ) ) { 
  2. require_once ABSPATH . WPINC . '/link-template.php'; 
  3.  
  4. // Optional. Post ID. Default is the ID of the global `$post`. 
  5. $post_id = -1; 
  6.  
  7. // Optional. Feed type. Default empty. 
  8. $feed = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_post_comments_feed_link($post_id, $feed); 
  12.  

Defined (1)

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

/wp-includes/link-template.php  
  1. function get_post_comments_feed_link( $post_id = 0, $feed = '' ) { 
  2. $post_id = absint( $post_id ); 
  3.  
  4. if ( ! $post_id ) 
  5. $post_id = get_the_ID(); 
  6.  
  7. if ( empty( $feed ) ) 
  8. $feed = get_default_feed(); 
  9.  
  10. $post = get_post( $post_id ); 
  11. $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent; 
  12.  
  13. if ( '' != get_option('permalink_structure') ) { 
  14. if ( 'page' == get_option('show_on_front') && $post_id == get_option('page_on_front') ) 
  15. $url = _get_page_link( $post_id ); 
  16. else 
  17. $url = get_permalink($post_id); 
  18.  
  19. if ( $unattached ) { 
  20. $url = home_url( '/feed/' ); 
  21. if ( $feed !== get_default_feed() ) { 
  22. $url .= "$feed/"; 
  23. $url = add_query_arg( 'attachment_id', $post_id, $url ); 
  24. } else { 
  25. $url = trailingslashit($url) . 'feed'; 
  26. if ( $feed != get_default_feed() ) 
  27. $url .= "/$feed"; 
  28. $url = user_trailingslashit($url, 'single_feed'); 
  29. } else { 
  30. if ( $unattached ) { 
  31. $url = add_query_arg( array( 'feed' => $feed, 'attachment_id' => $post_id ), home_url( '/' ) ); 
  32. } elseif ( 'page' == $post->post_type ) { 
  33. $url = add_query_arg( array( 'feed' => $feed, 'page_id' => $post_id ), home_url( '/' ) ); 
  34. } else { 
  35. $url = add_query_arg( array( 'feed' => $feed, 'p' => $post_id ), home_url( '/' ) ); 
  36.  
  37. /** 
  38. * Filters the post comments feed permalink. 
  39. * @since 1.5.1 
  40. * @param string $url Post comments feed permalink. 
  41. */