comment_form_title()WP 2.7.0

Display text based on comment reply status.

Only affects users with JavaScript disabled.

No Hooks.

Return

null. Nothing.

Usage

comment_form_title( $no_reply_text, $reply_text, $link_to_parent );
$no_reply_text(string|false)
Text to display when not replying to a comment.
Default: false
$reply_text(string|false)
Text to display when replying to a comment. Accepts "%s" for the author of the comment being replied to.
Default: false
$link_to_parent(true|false)
Boolean to control making the author's name a link to their comment.
Default: true

Examples

0

#1 Create a header for the comment form and "wrap" it in the H3 tag: [auto-translate]

<h3><?php comment_form_title(); ?></h3>
0

#2 Display our own texts, different from the default ones:

<h3><?php comment_form_title( 'Comment', 'Reply to commenter: %s' ); ?></h3>

Notes

  • Global. WP_Comment. $comment Global comment object.

Changelog

Since 2.7.0 Introduced.

comment_form_title() code WP 6.1.1

function comment_form_title( $no_reply_text = false, $reply_text = false, $link_to_parent = true ) {
	global $comment;

	if ( false === $no_reply_text ) {
		$no_reply_text = __( 'Leave a Reply' );
	}

	if ( false === $reply_text ) {
		/* translators: %s: Author of the comment being replied to. */
		$reply_text = __( 'Leave a Reply to %s' );
	}

	$reply_to_id = isset( $_GET['replytocom'] ) ? (int) $_GET['replytocom'] : 0;

	if ( 0 == $reply_to_id ) {
		echo $no_reply_text;
	} else {
		// Sets the global so that template tags can be used in the comment form.
		$comment = get_comment( $reply_to_id );

		if ( $link_to_parent ) {
			$author = '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author( $comment ) . '</a>';
		} else {
			$author = get_comment_author( $comment );
		}

		printf( $reply_text, $author );
	}
}