get_cancel_comment_reply_link()WP 2.7.0

Retrieve HTML content for cancel comment reply link.

Hooks from the function

Return

String.

Usage

get_cancel_comment_reply_link( $text );
$text(string)
Text to display for cancel reply link. If empty. Default empty.
Default: 'Click here to cancel reply'

Examples

0

#1 Display a link that cancels the response to a certain comment:

$cancel_link = get_cancel_comment_reply_link();

echo $cancel_link;

Changelog

Since 2.7.0 Introduced.

get_cancel_comment_reply_link() code WP 6.1.1

function get_cancel_comment_reply_link( $text = '' ) {
	if ( empty( $text ) ) {
		$text = __( 'Click here to cancel reply.' );
	}

	$style = isset( $_GET['replytocom'] ) ? '' : ' style="display:none;"';
	$link  = esc_html( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond';

	$formatted_link = '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>';

	/**
	 * Filters the cancel comment reply link HTML.
	 *
	 * @since 2.7.0
	 *
	 * @param string $formatted_link The HTML-formatted cancel comment reply link.
	 * @param string $link           Cancel comment reply link URL.
	 * @param string $text           Cancel comment reply link text.
	 */
	return apply_filters( 'cancel_comment_reply_link', $formatted_link, $link, $text );
}