# get_comment_reply_link()

URL: https://chugunov.pro/api-wordpress/functions/get_comment_reply_link/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.7.0.

## Сигнатура

```php
get_comment_reply_link( array $args = array(), int|WP_Comment $comment = null, int|WP_Post $post = null ): string|false|null
```

## Описание

Получает HTML-содержимое для ссылки «ответить на комментарий».

## Параметры

- `$args` `array` — необязательный, по умолчанию `array()`. Переопределяет аргументы по умолчанию.
  
  add_below stringПервая часть селектора, используемого для определения комментария, под которым размещается ответ.
  
  Итоговое значение передаётся как первый параметр в addComment.moveForm() и объединяется в виде $add_below-$comment->comment_ID. По умолчанию 'comment'.
  
  respond_id stringСелектор, определяющий комментарий, на который отвечают. Передаётся как третий параметр в addComment.moveForm() и добавляется к URL ссылки в виде значения-хэша.
  
  По умолчанию 'respond'.
  
  reply_text stringВидимый текст ссылки «Ответить». По умолчанию 'Reply'.
  
  reply_to_text stringДоступное имя ссылки «Ответить», где %s используется как заполнитель для имени автора комментария. По умолчанию ‘Reply to %s’.
  
  Должно начинаться с видимого значения reply_text.
  
  show_reply_to_text boolИспользовать ли reply_to_text как видимый текст ссылки. По умолчанию false.
  
  login_text stringТекст ссылки для ответа, если пользователь не авторизован. По умолчанию ‘Log in to Reply’.
  
  max_depth intМаксимальная глубина дерева комментариев. По умолчанию 0.
  
  depth intГлубина нового комментария. Должна быть больше 0 и меньше значения опции 'thread_comments_depth', заданной в разделе «Настройки» > «Обсуждение». По умолчанию 0.
  
  before stringТекст или HTML, добавляемый перед ссылкой на ответ.
  
  after stringТекст или HTML, добавляемый после ссылки на ответ.
- `$comment` `int|WP_Comment` — необязательный, по умолчанию `null`. Комментарий, на который отвечают. По умолчанию — текущий комментарий.
- `$post` `int|WP_Post` — необязательный, по умолчанию `null`. ID записи или объект WP_Post, на котором будет отображён комментарий.
  
  По умолчанию — текущая запись.

## Возвращаемое значение

`string|false|null`

## Исходный код

Файл: `wp-includes/comment-template.php:1755`

```php
function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
	$defaults = array(
		'add_below'          => 'comment',
		'respond_id'         => 'respond',
		/* translators: Comment reply button text. */
		'reply_text'         => _x( 'Reply', 'verb' ),
		/* translators: Comment reply button text. %s: Comment author name. */
		'reply_to_text'      => __( 'Reply to %s' ),
		'login_text'         => __( 'Log in to Reply' ),
		'max_depth'          => 0,
		'depth'              => 0,
		'before'             => '',
		'after'              => '',
		'show_reply_to_text' => false,
	);

	$args = wp_parse_args( $args, $defaults );

	$args['max_depth'] = (int) $args['max_depth'];
	$args['depth']     = (int) $args['depth'];

	if ( 0 === $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
		return null;
	}

	$comment = get_comment( $comment );

	if ( empty( $comment ) ) {
		return null;
	}

	if ( empty( $post ) ) {
		$post = $comment->comment_post_ID;
	}

	$post = get_post( $post );

	if ( ! comments_open( $post->ID ) ) {
		return false;
	}

	if ( get_option( 'page_comments' ) ) {
		$permalink = str_replace( '#comment-' . $comment->comment_ID, '', get_comment_link( $comment ) );
	} else {
		$permalink = get_permalink( $post->ID );
	}

	/**
	 * Filters the comment reply link arguments.
	 *
	 * @since 4.1.0
	 *
	 * @param array      $args    Comment reply link arguments. See get_comment_reply_link()
	 *                            for more information on accepted arguments.
	 * @param WP_Comment $comment The object of the comment being replied to.
	 * @param WP_Post    $post    The WP_Post object.
	 */
	$args = apply_filters( 'comment_reply_link_args', $args, $comment, $post );

	if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
		$link = sprintf(
			'<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
			esc_url( wp_login_url( get_permalink() ) ),
			$args['login_text']
		);
	} else {
		$data_attributes = array(
			'commentid'      => $comment->comment_ID,
			'postid'         => $post->ID,
			'belowelement'   => $args['add_below'] . '-' . $comment->comment_ID,
			'respondelement' => $args['respond_id'],
			'replyto'        => sprintf( $args['reply_to_text'], get_comment_author( $comment ) ),
		);

		$data_attribute_string = '';

		foreach ( $data_attributes as $name => $value ) {
			$data_attribute_string .= " data-{$name}=\"" . esc_attr( $value ) . '"';
		}

		$data_attribute_string = trim( $data_attribute_string );

		$reply_text = $args['show_reply_to_text']
			? sprintf( $args['reply_to_text'], get_comment_author( $comment ) )
			: $args['reply_text'];

		$aria_label = $args['show_reply_to_text'] ? '' : sprintf( $args['reply_to_text'], get_comment_author( $comment ) );

		$link = sprintf(
			'<a rel="nofollow" class="comment-reply-link" href="%s" %s%s>%s</a>',
			esc_url(
				add_query_arg(
					array(
						'replytocom'      => $comment->comment_ID,
						'unapproved'      => false,
						'moderation-hash' => false,
					),
					$permalink
				)
			) . '#' . $args['respond_id'],
			$data_attribute_string,
			$aria_label ? ' aria-label="' . esc_attr( $aria_label ) . '"' : '',
			$reply_text
		);
	}

	$comment_reply_link = $args['before'] . $link . $args['after'];

	/**
	 * Filters the comment reply link.
	 *
	 * @since 2.7.0
	 *
	 * @param string     $comment_reply_link The HTML markup for the comment reply link.
	 * @param array      $args               An array of arguments overriding the defaults.
	 * @param WP_Comment $comment            The object of the comment being replied.
	 * @param WP_Post    $post               The WP_Post object.
	 */
	return apply_filters( 'comment_reply_link', $comment_reply_link, $args, $comment, $post );
}
```

## История изменений

- 4.4.0 — Added the ability for $comment to also accept a WP_Comment object.
- 2.7.0 — Introduced.

## Связанные

Использует: [`wp_login_url`](https://chugunov.pro/api-wordpress/functions/wp_login_url/), [`comments_open`](https://chugunov.pro/api-wordpress/functions/comments_open/), [`get_comment_link`](https://chugunov.pro/api-wordpress/functions/get_comment_link/), [`get_comment_author`](https://chugunov.pro/api-wordpress/functions/get_comment_author/), [`_x`](https://chugunov.pro/api-wordpress/functions/_x/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`esc_url`](https://chugunov.pro/api-wordpress/functions/esc_url/), [`esc_attr`](https://chugunov.pro/api-wordpress/functions/esc_attr/), [`is_user_logged_in`](https://chugunov.pro/api-wordpress/functions/is_user_logged_in/), [`wp_parse_args`](https://chugunov.pro/api-wordpress/functions/wp_parse_args/), [`add_query_arg`](https://chugunov.pro/api-wordpress/functions/add_query_arg/), [`get_permalink`](https://chugunov.pro/api-wordpress/functions/get_permalink/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_option`](https://chugunov.pro/api-wordpress/functions/get_option/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/), [`get_comment`](https://chugunov.pro/api-wordpress/functions/get_comment/).
Используется в: [`comment_reply_link`](https://chugunov.pro/api-wordpress/functions/comment_reply_link/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_comment_reply_link/
