get_post_comments_feed_link

The timeline below displays how wordpress function get_post_comments_feed_link has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 5.8

/**
 * Retrieves the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int    $post_id Optional. Post ID. Default is the ID of the global `$post`.
 * @param string $feed    Optional. Feed type. Possible values include 'rss2', 'atom'.
 *                        Default is the value of get_default_feed().
 * @return string The permalink for the comments feed for the given post on success, empty string on failure.
 */
function get_post_comments_feed_link($post_id = 0, $feed = '')
{
    $post_id = absint($post_id);
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (empty($feed)) {
        $feed = get_default_feed();
    }
    $post = get_post($post_id);
    // Bail out if the post does not exist.
    if (!$post instanceof WP_Post) {
        return '';
    }
    $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
    if (get_option('permalink_structure')) {
        if ('page' === get_option('show_on_front') && get_option('page_on_front') == $post_id) {
            $url = _get_page_link($post_id);
        } else {
            $url = get_permalink($post_id);
        }
        if ($unattached) {
            $url = home_url('/feed/');
            if (get_default_feed() !== $feed) {
                $url .= "{$feed}/";
            }
            $url = add_query_arg('attachment_id', $post_id, $url);
        } else {
            $url = trailingslashit($url) . 'feed';
            if (get_default_feed() != $feed) {
                $url .= "/{$feed}";
            }
            $url = user_trailingslashit($url, 'single_feed');
        }
    } else if ($unattached) {
        $url = add_query_arg(array('feed' => $feed, 'attachment_id' => $post_id), home_url('/'));
    } elseif ('page' === $post->post_type) {
        $url = add_query_arg(array('feed' => $feed, 'page_id' => $post_id), home_url('/'));
    } else {
        $url = add_query_arg(array('feed' => $feed, 'p' => $post_id), home_url('/'));
    }
    /**
     * Filters the post comments feed permalink.
     *
     * @since 1.5.1
     *
     * @param string $url Post comments feed permalink.
     */
    return apply_filters('post_comments_feed_link', $url);
}

WordPress Version: 5.5

/**
 * Retrieves the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int    $post_id Optional. Post ID. Default is the ID of the global `$post`.
 * @param string $feed    Optional. Feed type. Possible values include 'rss2', 'atom'.
 *                        Default is the value of get_default_feed().
 * @return string The permalink for the comments feed for the given post.
 */
function get_post_comments_feed_link($post_id = 0, $feed = '')
{
    $post_id = absint($post_id);
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (empty($feed)) {
        $feed = get_default_feed();
    }
    $post = get_post($post_id);
    $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
    if (get_option('permalink_structure')) {
        if ('page' === get_option('show_on_front') && get_option('page_on_front') == $post_id) {
            $url = _get_page_link($post_id);
        } else {
            $url = get_permalink($post_id);
        }
        if ($unattached) {
            $url = home_url('/feed/');
            if (get_default_feed() !== $feed) {
                $url .= "{$feed}/";
            }
            $url = add_query_arg('attachment_id', $post_id, $url);
        } else {
            $url = trailingslashit($url) . 'feed';
            if (get_default_feed() != $feed) {
                $url .= "/{$feed}";
            }
            $url = user_trailingslashit($url, 'single_feed');
        }
    } else if ($unattached) {
        $url = add_query_arg(array('feed' => $feed, 'attachment_id' => $post_id), home_url('/'));
    } elseif ('page' === $post->post_type) {
        $url = add_query_arg(array('feed' => $feed, 'page_id' => $post_id), home_url('/'));
    } else {
        $url = add_query_arg(array('feed' => $feed, 'p' => $post_id), home_url('/'));
    }
    /**
     * Filters the post comments feed permalink.
     *
     * @since 1.5.1
     *
     * @param string $url Post comments feed permalink.
     */
    return apply_filters('post_comments_feed_link', $url);
}

WordPress Version: 5.4

/**
 * Retrieves the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int    $post_id Optional. Post ID. Default is the ID of the global `$post`.
 * @param string $feed    Optional. Feed type. Possible values include 'rss2', 'atom'.
 *                        Default is the value of get_default_feed().
 * @return string The permalink for the comments feed for the given post.
 */
function get_post_comments_feed_link($post_id = 0, $feed = '')
{
    $post_id = absint($post_id);
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (empty($feed)) {
        $feed = get_default_feed();
    }
    $post = get_post($post_id);
    $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
    if ('' != get_option('permalink_structure')) {
        if ('page' === get_option('show_on_front') && get_option('page_on_front') == $post_id) {
            $url = _get_page_link($post_id);
        } else {
            $url = get_permalink($post_id);
        }
        if ($unattached) {
            $url = home_url('/feed/');
            if (get_default_feed() !== $feed) {
                $url .= "{$feed}/";
            }
            $url = add_query_arg('attachment_id', $post_id, $url);
        } else {
            $url = trailingslashit($url) . 'feed';
            if (get_default_feed() != $feed) {
                $url .= "/{$feed}";
            }
            $url = user_trailingslashit($url, 'single_feed');
        }
    } else if ($unattached) {
        $url = add_query_arg(array('feed' => $feed, 'attachment_id' => $post_id), home_url('/'));
    } elseif ('page' === $post->post_type) {
        $url = add_query_arg(array('feed' => $feed, 'page_id' => $post_id), home_url('/'));
    } else {
        $url = add_query_arg(array('feed' => $feed, 'p' => $post_id), home_url('/'));
    }
    /**
     * Filters the post comments feed permalink.
     *
     * @since 1.5.1
     *
     * @param string $url Post comments feed permalink.
     */
    return apply_filters('post_comments_feed_link', $url);
}

WordPress Version: 5.3

/**
 * Retrieves the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int    $post_id Optional. Post ID. Default is the ID of the global `$post`.
 * @param string $feed    Optional. Feed type. Possible values include 'rss2', 'atom'.
 *                        Default is the value of get_default_feed().
 * @return string The permalink for the comments feed for the given post.
 */
function get_post_comments_feed_link($post_id = 0, $feed = '')
{
    $post_id = absint($post_id);
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (empty($feed)) {
        $feed = get_default_feed();
    }
    $post = get_post($post_id);
    $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
    if ('' != get_option('permalink_structure')) {
        if ('page' == get_option('show_on_front') && $post_id == get_option('page_on_front')) {
            $url = _get_page_link($post_id);
        } else {
            $url = get_permalink($post_id);
        }
        if ($unattached) {
            $url = home_url('/feed/');
            if ($feed !== get_default_feed()) {
                $url .= "{$feed}/";
            }
            $url = add_query_arg('attachment_id', $post_id, $url);
        } else {
            $url = trailingslashit($url) . 'feed';
            if ($feed != get_default_feed()) {
                $url .= "/{$feed}";
            }
            $url = user_trailingslashit($url, 'single_feed');
        }
    } else if ($unattached) {
        $url = add_query_arg(array('feed' => $feed, 'attachment_id' => $post_id), home_url('/'));
    } elseif ('page' == $post->post_type) {
        $url = add_query_arg(array('feed' => $feed, 'page_id' => $post_id), home_url('/'));
    } else {
        $url = add_query_arg(array('feed' => $feed, 'p' => $post_id), home_url('/'));
    }
    /**
     * Filters the post comments feed permalink.
     *
     * @since 1.5.1
     *
     * @param string $url Post comments feed permalink.
     */
    return apply_filters('post_comments_feed_link', $url);
}

WordPress Version: 4.6

/**
 * Retrieves the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int    $post_id Optional. Post ID. Default is the ID of the global `$post`.
 * @param string $feed    Optional. Feed type. Default empty.
 * @return string The permalink for the comments feed for the given post.
 */
function get_post_comments_feed_link($post_id = 0, $feed = '')
{
    $post_id = absint($post_id);
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (empty($feed)) {
        $feed = get_default_feed();
    }
    $post = get_post($post_id);
    $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
    if ('' != get_option('permalink_structure')) {
        if ('page' == get_option('show_on_front') && $post_id == get_option('page_on_front')) {
            $url = _get_page_link($post_id);
        } else {
            $url = get_permalink($post_id);
        }
        if ($unattached) {
            $url = home_url('/feed/');
            if ($feed !== get_default_feed()) {
                $url .= "{$feed}/";
            }
            $url = add_query_arg('attachment_id', $post_id, $url);
        } else {
            $url = trailingslashit($url) . 'feed';
            if ($feed != get_default_feed()) {
                $url .= "/{$feed}";
            }
            $url = user_trailingslashit($url, 'single_feed');
        }
    } else if ($unattached) {
        $url = add_query_arg(array('feed' => $feed, 'attachment_id' => $post_id), home_url('/'));
    } elseif ('page' == $post->post_type) {
        $url = add_query_arg(array('feed' => $feed, 'page_id' => $post_id), home_url('/'));
    } else {
        $url = add_query_arg(array('feed' => $feed, 'p' => $post_id), home_url('/'));
    }
    /**
     * Filters the post comments feed permalink.
     *
     * @since 1.5.1
     *
     * @param string $url Post comments feed permalink.
     */
    return apply_filters('post_comments_feed_link', $url);
}

WordPress Version: 4.4

/**
 * Retrieve the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int    $post_id Optional. Post ID.
 * @param string $feed    Optional. Feed type.
 * @return string The permalink for the comments feed for the given post.
 */
function get_post_comments_feed_link($post_id = 0, $feed = '')
{
    $post_id = absint($post_id);
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (empty($feed)) {
        $feed = get_default_feed();
    }
    $post = get_post($post_id);
    $unattached = 'attachment' === $post->post_type && 0 === (int) $post->post_parent;
    if ('' != get_option('permalink_structure')) {
        if ('page' == get_option('show_on_front') && $post_id == get_option('page_on_front')) {
            $url = _get_page_link($post_id);
        } else {
            $url = get_permalink($post_id);
        }
        if ($unattached) {
            $url = home_url('/feed/');
            if ($feed !== get_default_feed()) {
                $url .= "{$feed}/";
            }
            $url = add_query_arg('attachment_id', $post_id, $url);
        } else {
            $url = trailingslashit($url) . 'feed';
            if ($feed != get_default_feed()) {
                $url .= "/{$feed}";
            }
            $url = user_trailingslashit($url, 'single_feed');
        }
    } else if ($unattached) {
        $url = add_query_arg(array('feed' => $feed, 'attachment_id' => $post_id), home_url('/'));
    } elseif ('page' == $post->post_type) {
        $url = add_query_arg(array('feed' => $feed, 'page_id' => $post_id), home_url('/'));
    } else {
        $url = add_query_arg(array('feed' => $feed, 'p' => $post_id), home_url('/'));
    }
    /**
     * Filter the post comments feed permalink.
     *
     * @since 1.5.1
     *
     * @param string $url Post comments feed permalink.
     */
    return apply_filters('post_comments_feed_link', $url);
}

WordPress Version: 4.3

/**
 * Retrieve the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int    $post_id Optional. Post ID.
 * @param string $feed    Optional. Feed type.
 * @return string The permalink for the comments feed for the given post.
 */
function get_post_comments_feed_link($post_id = 0, $feed = '')
{
    $post_id = absint($post_id);
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (empty($feed)) {
        $feed = get_default_feed();
    }
    if ('' != get_option('permalink_structure')) {
        if ('page' == get_option('show_on_front') && $post_id == get_option('page_on_front')) {
            $url = _get_page_link($post_id);
        } else {
            $url = get_permalink($post_id);
        }
        $url = trailingslashit($url) . 'feed';
        if ($feed != get_default_feed()) {
            $url .= "/{$feed}";
        }
        $url = user_trailingslashit($url, 'single_feed');
    } else {
        $type = get_post_field('post_type', $post_id);
        if ('page' == $type) {
            $url = add_query_arg(array('feed' => $feed, 'page_id' => $post_id), home_url('/'));
        } else {
            $url = add_query_arg(array('feed' => $feed, 'p' => $post_id), home_url('/'));
        }
    }
    /**
     * Filter the post comments feed permalink.
     *
     * @since 1.5.1
     *
     * @param string $url Post comments feed permalink.
     */
    return apply_filters('post_comments_feed_link', $url);
}

WordPress Version: 4.1

/**
 * Retrieve the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int $post_id Optional. Post ID.
 * @param string $feed Optional. Feed type.
 * @return string The permalink for the comments feed for the given post.
 */
function get_post_comments_feed_link($post_id = 0, $feed = '')
{
    $post_id = absint($post_id);
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (empty($feed)) {
        $feed = get_default_feed();
    }
    if ('' != get_option('permalink_structure')) {
        if ('page' == get_option('show_on_front') && $post_id == get_option('page_on_front')) {
            $url = _get_page_link($post_id);
        } else {
            $url = get_permalink($post_id);
        }
        $url = trailingslashit($url) . 'feed';
        if ($feed != get_default_feed()) {
            $url .= "/{$feed}";
        }
        $url = user_trailingslashit($url, 'single_feed');
    } else {
        $type = get_post_field('post_type', $post_id);
        if ('page' == $type) {
            $url = add_query_arg(array('feed' => $feed, 'page_id' => $post_id), home_url('/'));
        } else {
            $url = add_query_arg(array('feed' => $feed, 'p' => $post_id), home_url('/'));
        }
    }
    /**
     * Filter the post comments feed permalink.
     *
     * @since 1.5.1
     *
     * @param string $url Post comments feed permalink.
     */
    return apply_filters('post_comments_feed_link', $url);
}

WordPress Version: 3.9

/**
 * Retrieve the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int $post_id Optional. Post ID.
 * @param string $feed Optional. Feed type.
 * @return string
 */
function get_post_comments_feed_link($post_id = 0, $feed = '')
{
    $post_id = absint($post_id);
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (empty($feed)) {
        $feed = get_default_feed();
    }
    if ('' != get_option('permalink_structure')) {
        if ('page' == get_option('show_on_front') && $post_id == get_option('page_on_front')) {
            $url = _get_page_link($post_id);
        } else {
            $url = get_permalink($post_id);
        }
        $url = trailingslashit($url) . 'feed';
        if ($feed != get_default_feed()) {
            $url .= "/{$feed}";
        }
        $url = user_trailingslashit($url, 'single_feed');
    } else {
        $type = get_post_field('post_type', $post_id);
        if ('page' == $type) {
            $url = add_query_arg(array('feed' => $feed, 'page_id' => $post_id), home_url('/'));
        } else {
            $url = add_query_arg(array('feed' => $feed, 'p' => $post_id), home_url('/'));
        }
    }
    /**
     * Filter the post comments feed permalink.
     *
     * @since 1.5.1
     *
     * @param string $url Post comments feed permalink.
     */
    return apply_filters('post_comments_feed_link', $url);
}

WordPress Version: 3.7

/**
 * Retrieve the permalink for the post comments feed.
 *
 * @since 2.2.0
 *
 * @param int $post_id Optional. Post ID.
 * @param string $feed Optional. Feed type.
 * @return string
 */
function get_post_comments_feed_link($post_id = 0, $feed = '')
{
    $post_id = absint($post_id);
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    if (empty($feed)) {
        $feed = get_default_feed();
    }
    if ('' != get_option('permalink_structure')) {
        if ('page' == get_option('show_on_front') && $post_id == get_option('page_on_front')) {
            $url = _get_page_link($post_id);
        } else {
            $url = get_permalink($post_id);
        }
        $url = trailingslashit($url) . 'feed';
        if ($feed != get_default_feed()) {
            $url .= "/{$feed}";
        }
        $url = user_trailingslashit($url, 'single_feed');
    } else {
        $type = get_post_field('post_type', $post_id);
        if ('page' == $type) {
            $url = add_query_arg(array('feed' => $feed, 'page_id' => $post_id), home_url('/'));
        } else {
            $url = add_query_arg(array('feed' => $feed, 'p' => $post_id), home_url('/'));
        }
    }
    return apply_filters('post_comments_feed_link', $url);
}