get_comment_author_link

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

WordPress Version: 6.3

/**
 * Retrieves the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_id argument is empty.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to get the author's link.
 *                                   Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_id = 0)
{
    $comment = get_comment($comment_id);
    $comment_id = (!empty($comment->comment_ID)) ? $comment->comment_ID : (string) $comment_id;
    $comment_author_url = get_comment_author_url($comment);
    $comment_author = get_comment_author($comment);
    if (empty($comment_author_url) || 'http://' === $comment_author_url) {
        $comment_author_link = $comment_author;
    } else {
        $rel_parts = array('ugc');
        if (!wp_is_internal_link($comment_author_url)) {
            $rel_parts = array_merge($rel_parts, array('external', 'nofollow'));
        }
        /**
         * Filters the rel attributes of the comment author's link.
         *
         * @since 6.2.0
         *
         * @param string[]   $rel_parts An array of strings representing the rel tags
         *                              which will be joined into the anchor's rel attribute.
         * @param WP_Comment $comment   The comment object.
         */
        $rel_parts = apply_filters('comment_author_link_rel', $rel_parts, $comment);
        $rel = implode(' ', $rel_parts);
        $rel = esc_attr($rel);
        // Empty space before 'rel' is necessary for later sprintf().
        $rel = (!empty($rel)) ? sprintf(' rel="%s"', $rel) : '';
        $comment_author_link = sprintf('<a href="%1$s" class="url"%2$s>%3$s</a>', $comment_author_url, $rel, $comment_author);
    }
    /**
     * Filters the comment author's link for display.
     *
     * @since 1.5.0
     * @since 4.1.0 The `$comment_author` and `$comment_id` parameters were added.
     *
     * @param string $comment_author_link The HTML-formatted comment author link.
     *                                    Empty for an invalid URL.
     * @param string $comment_author      The comment author's username.
     * @param string $comment_id          The comment ID as a numeric string.
     */
    return apply_filters('get_comment_author_link', $comment_author_link, $comment_author, $comment_id);
}

WordPress Version: 6.2

/**
 * Retrieves the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_id argument is empty.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_id` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_id Optional. WP_Comment or the ID of the comment for which to get the author's link.
 *                                   Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_id = 0)
{
    $comment = get_comment($comment_id);
    $comment_id = (!empty($comment->comment_ID)) ? $comment->comment_ID : (string) $comment_id;
    $url = get_comment_author_url($comment);
    $author = get_comment_author($comment);
    if (empty($url) || 'http://' === $url) {
        $return = $author;
    } else {
        $rel_parts = array('ugc');
        if (!wp_is_internal_link($url)) {
            $rel_parts = array_merge($rel_parts, array('external', 'nofollow'));
        }
        /**
         * Filters the rel attributes of the comment author's link.
         *
         * @since 6.2.0
         *
         * @param string[]   $rel_parts An array of strings representing the rel tags
         *                              which will be joined into the anchor's rel attribute.
         * @param WP_Comment $comment   The comment object.
         */
        $rel_parts = apply_filters('comment_author_link_rel', $rel_parts, $comment);
        $rel = implode(' ', $rel_parts);
        $rel = esc_attr($rel);
        // Empty space before 'rel' is necessary for later sprintf().
        $rel = (!empty($rel)) ? sprintf(' rel="%s"', $rel) : '';
        $return = sprintf('<a href="%1$s" class="url"%2$s>%3$s</a>', $url, $rel, $author);
    }
    /**
     * Filters the comment author's link for display.
     *
     * @since 1.5.0
     * @since 4.1.0 The `$author` and `$comment_id` parameters were added.
     *
     * @param string $return     The HTML-formatted comment author link.
     *                           Empty for an invalid URL.
     * @param string $author     The comment author's username.
     * @param string $comment_id The comment ID as a numeric string.
     */
    return apply_filters('get_comment_author_link', $return, $author, $comment_id);
}

WordPress Version: 5.9

/**
 * Retrieves the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.
 *                                   Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $url = get_comment_author_url($comment);
    $author = get_comment_author($comment);
    if (empty($url) || 'http://' === $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow ugc' class='url'>{$author}</a>";
    }
    /**
     * Filters the comment author's link for display.
     *
     * @since 1.5.0
     * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
     *
     * @param string $return     The HTML-formatted comment author link.
     *                           Empty for an invalid URL.
     * @param string $author     The comment author's username.
     * @param string $comment_ID The comment ID as a numeric string.
     */
    return apply_filters('get_comment_author_link', $return, $author, $comment->comment_ID);
}

WordPress Version: 5.5

/**
 * Retrieves the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.
 *                                   Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $url = get_comment_author_url($comment);
    $author = get_comment_author($comment);
    if (empty($url) || 'http://' === $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow ugc' class='url'>{$author}</a>";
    }
    /**
     * Filters the comment author's link for display.
     *
     * @since 1.5.0
     * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
     *
     * @param string $return     The HTML-formatted comment author link.
     *                           Empty for an invalid URL.
     * @param string $author     The comment author's username.
     * @param int    $comment_ID The comment ID.
     */
    return apply_filters('get_comment_author_link', $return, $author, $comment->comment_ID);
}

WordPress Version: 5.4

/**
 * Retrieves the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.
 *                                   Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $url = get_comment_author_url($comment);
    $author = get_comment_author($comment);
    if (empty($url) || 'http://' == $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow ugc' class='url'>{$author}</a>";
    }
    /**
     * Filters the comment author's link for display.
     *
     * @since 1.5.0
     * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
     *
     * @param string $return     The HTML-formatted comment author link.
     *                           Empty for an invalid URL.
     * @param string $author     The comment author's username.
     * @param int    $comment_ID The comment ID.
     */
    return apply_filters('get_comment_author_link', $return, $author, $comment->comment_ID);
}

WordPress Version: 5.3

/**
 * Retrieve the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.
 *                                   Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $url = get_comment_author_url($comment);
    $author = get_comment_author($comment);
    if (empty($url) || 'http://' == $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow ugc' class='url'>{$author}</a>";
    }
    /**
     * Filters the comment author's link for display.
     *
     * @since 1.5.0
     * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
     *
     * @param string $return     The HTML-formatted comment author link.
     *                           Empty for an invalid URL.
     * @param string $author     The comment author's username.
     * @param int    $comment_ID The comment ID.
     */
    return apply_filters('get_comment_author_link', $return, $author, $comment->comment_ID);
}

WordPress Version: 5.1

/**
 * Retrieve the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.
 *                                   Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $url = get_comment_author_url($comment);
    $author = get_comment_author($comment);
    if (empty($url) || 'http://' == $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow' class='url'>{$author}</a>";
    }
    /**
     * Filters the comment author's link for display.
     *
     * @since 1.5.0
     * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
     *
     * @param string $return     The HTML-formatted comment author link.
     *                           Empty for an invalid URL.
     * @param string $author     The comment author's username.
     * @param int    $comment_ID The comment ID.
     */
    return apply_filters('get_comment_author_link', $return, $author, $comment->comment_ID);
}

WordPress Version: 4.6

/**
 * Retrieve the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.
 *									 Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $url = get_comment_author_url($comment);
    $author = get_comment_author($comment);
    if (empty($url) || 'http://' == $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow' class='url'>{$author}</a>";
    }
    /**
     * Filters the comment author's link for display.
     *
     * @since 1.5.0
     * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
     *
     * @param string $return     The HTML-formatted comment author link.
     *                           Empty for an invalid URL.
     * @param string $author     The comment author's username.
     * @param int    $comment_ID The comment ID.
     */
    return apply_filters('get_comment_author_link', $return, $author, $comment->comment_ID);
}

WordPress Version: 4.4

/**
 * Retrieve the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 * @since 4.4.0 Added the ability for `$comment_ID` to also accept a WP_Comment object.
 *
 * @param int|WP_Comment $comment_ID Optional. WP_Comment or the ID of the comment for which to get the author's link.
 *									 Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $comment = get_comment($comment_ID);
    $url = get_comment_author_url($comment);
    $author = get_comment_author($comment);
    if (empty($url) || 'http://' == $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow' class='url'>{$author}</a>";
    }
    /**
     * Filter the comment author's link for display.
     *
     * @since 1.5.0
     * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
     *
     * @param string $return     The HTML-formatted comment author link.
     *                           Empty for an invalid URL.
     * @param string $author     The comment author's username.
     * @param int    $comment_ID The comment ID.
     */
    return apply_filters('get_comment_author_link', $return, $author, $comment->comment_ID);
}

WordPress Version: 4.1

/**
 * Retrieve the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 *
 * @param int $comment_ID ID of the comment for which to get the author's link.
 *                        Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $url = get_comment_author_url($comment_ID);
    $author = get_comment_author($comment_ID);
    if (empty($url) || 'http://' == $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow' class='url'>{$author}</a>";
    }
    /**
     * Filter the comment author's link for display.
     *
     * @since 1.5.0
     * @since 4.1.0 The `$author` and `$comment_ID` parameters were added.
     *
     * @param string $return     The HTML-formatted comment author link.
     *                           Empty for an invalid URL.
     * @param string $author     The comment author's username.
     * @param int    $comment_ID The comment ID.
     */
    return apply_filters('get_comment_author_link', $return, $author, $comment_ID);
}

WordPress Version: 3.9

/**
 * Retrieve the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 *
 * @param int $comment_ID ID of the comment for which to get the author's link.
 *                        Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $url = get_comment_author_url($comment_ID);
    $author = get_comment_author($comment_ID);
    if (empty($url) || 'http://' == $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow' class='url'>{$author}</a>";
    }
    /**
     * Filter the comment author's link for display.
     *
     * @since 1.5.0
     *
     * @param string $return The HTML-formatted comment author link.
     *                       Empty for an invalid URL.
     */
    return apply_filters('get_comment_author_link', $return);
}

WordPress Version: 3.8

/**
 * Retrieve the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 *
 * @param int $comment_ID Optional. The ID of the comment for which to get the author's link. Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $url = get_comment_author_url($comment_ID);
    $author = get_comment_author($comment_ID);
    if (empty($url) || 'http://' == $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow' class='url'>{$author}</a>";
    }
    /**
     * Filter the comment author's link for display.
     *
     * @since 1.5.0
     *
     * @param string $return The HTML-formatted comment author link. Empty for an invalid URL.
     */
    return apply_filters('get_comment_author_link', $return);
}

WordPress Version: 3.7

/**
 * Retrieve the HTML link to the URL of the author of the current comment.
 *
 * Both get_comment_author_url() and get_comment_author() rely on get_comment(),
 * which falls back to the global comment variable if the $comment_ID argument is empty.
 *
 * @since 1.5.0
 *
 * @param int $comment_ID Optional. The ID of the comment for which to get the author's link. Default current comment.
 * @return string The comment author name or HTML link for author's URL.
 */
function get_comment_author_link($comment_ID = 0)
{
    $url = get_comment_author_url($comment_ID);
    $author = get_comment_author($comment_ID);
    if (empty($url) || 'http://' == $url) {
        $return = $author;
    } else {
        $return = "<a href='{$url}' rel='external nofollow' class='url'>{$author}</a>";
    }
    /**
     * Filter the comment author's link for display.
     *
     * @since 1.5.2
     *
     * @param string $return The HTML-formatted comment author link. Empty for an invalid URL.
     */
    return apply_filters('get_comment_author_link', $return);
}