get_comment_author_url_link( string $link_text = , string $before = , string $after = , int|WP_Comment $comment ): string

Retrieves the HTML link of the URL of the author of the current comment.

Description

$link_text parameter is only used if the URL does not exist for the comment author. If the URL does exist then the URL will be used and the $link_text will be ignored.

Encapsulate the HTML link between the $before and $after. So it will appear in the order of $before, link, and finally $after.

Parameters

$link_textstringoptional
The text to display instead of the comment author’s email address.

Default:''

$beforestringoptional
The text or HTML to display before the email link.

Default:''

$afterstringoptional
The text or HTML to display after the email link.

Default:''

$commentint|WP_Commentoptional
Comment ID or WP_Comment object.
Default is the current comment.

Return

string The HTML link between the $before and $after parameters.

Source

function get_comment_author_url_link( $link_text = '', $before = '', $after = '', $comment = 0 ) {
	$comment_author_url = get_comment_author_url( $comment );

	$display = ( '' !== $link_text ) ? $link_text : $comment_author_url;
	$display = str_replace( 'http://www.', '', $display );
	$display = str_replace( 'http://', '', $display );

	if ( str_ends_with( $display, '/' ) ) {
		$display = substr( $display, 0, -1 );
	}

	$comment_author_url_link = $before . sprintf(
		'<a href="%1$s" rel="external">%2$s</a>',
		$comment_author_url,
		$display
	) . $after;

	/**
	 * Filters the comment author's returned URL link.
	 *
	 * @since 1.5.0
	 *
	 * @param string $comment_author_url_link The HTML-formatted comment author URL link.
	 */
	return apply_filters( 'get_comment_author_url_link', $comment_author_url_link );
}

Hooks

apply_filters( ‘get_comment_author_url_link’, string $comment_author_url_link )

Filters the comment author’s returned URL link.

Changelog

VersionDescription
4.6.0Added the $comment parameter.
1.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.