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( $link_text, $post );
$link_text(string)
Text to display for cancel reply link. If empty. Default empty.
Default: 'Click here to cancel reply'
$post(int|WP_Post|null)
The post the comment thread is being displayed for.
Default: current global post

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.
Since 6.2.0 Added the $post parameter.

get_cancel_comment_reply_link() code WP 6.5.3

function get_cancel_comment_reply_link( $link_text = '', $post = null ) {
	if ( empty( $link_text ) ) {
		$link_text = __( 'Click here to cancel reply.' );
	}

	$post        = get_post( $post );
	$reply_to_id = $post ? _get_comment_reply_id( $post->ID ) : 0;
	$link_style  = 0 !== $reply_to_id ? '' : ' style="display:none;"';
	$link_url    = esc_url( remove_query_arg( array( 'replytocom', 'unapproved', 'moderation-hash' ) ) ) . '#respond';

	$cancel_comment_reply_link = sprintf(
		'<a rel="nofollow" id="cancel-comment-reply-link" href="%1$s"%2$s>%3$s</a>',
		$link_url,
		$link_style,
		$link_text
	);

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