# get_comment_link()

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

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

## Сигнатура

```php
get_comment_link( WP_Comment|int|null $comment = null, array $args = array() ): string
```

## Описание

См. alsoget_page_of_comment()

## Параметры

- `$comment` `WP_Comment|int|null` — необязательный, по умолчанию `null`. Комментарий, который нужно получить. По умолчанию — текущий комментарий.
- `$args` `array` — необязательный, по умолчанию `array()`. Массив необязательных аргументов, переопределяющих значения по умолчанию.
  
  type stringПередаётся в get_page_of_comment() .
  
  page intТекущая страница комментариев, для расчёта постраничной навигации по комментариям.
  
  per_page intКоличество комментариев на странице для постраничной навигации.
  
  max_depth intПередаётся в get_page_of_comment() .
  
  cpage int|stringЗначение для параметра комментария "comment-page" или "cpage".
  
  Если задано, это значение переопределяет любое значение, рассчитанное из $page и $per_page.

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

`string`

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

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

```php
function get_comment_link( $comment = null, $args = array() ) {
	global $wp_rewrite, $in_comment_loop;

	$comment = get_comment( $comment );

	// Back-compat.
	if ( ! is_array( $args ) ) {
		$args = array( 'page' => $args );
	}

	$defaults = array(
		'type'      => 'all',
		'page'      => '',
		'per_page'  => '',
		'max_depth' => '',
		'cpage'     => null,
	);

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

	$comment_link = get_permalink( $comment->comment_post_ID );

	// The 'cpage' param takes precedence.
	if ( ! is_null( $args['cpage'] ) ) {
		$cpage = $args['cpage'];

		// No 'cpage' is provided, so we calculate one.
	} else {
		if ( '' === $args['per_page'] && get_option( 'page_comments' ) ) {
			$args['per_page'] = get_option( 'comments_per_page' );
		}

		if ( empty( $args['per_page'] ) ) {
			$args['per_page'] = 0;
			$args['page']     = 0;
		}

		$cpage = $args['page'];

		if ( '' === $cpage ) {
			if ( ! empty( $in_comment_loop ) ) {
				$cpage = (int) get_query_var( 'cpage' );
			} else {
				// Requires a database hit, so we only do it when we can't figure out from context.
				$cpage = get_page_of_comment( $comment->comment_ID, $args );
			}
		}

		/*
		 * If the default page displays the oldest comments, the permalinks for comments on the default page
		 * do not need a 'cpage' query var.
		 */
		if ( 'oldest' === get_option( 'default_comments_page' ) && 1 === $cpage ) {
			$cpage = '';
		}
	}

	if ( $cpage && get_option( 'page_comments' ) ) {
		if ( $wp_rewrite->using_permalinks() ) {
			$comment_link = trailingslashit( $comment_link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage;
		} else {
			$comment_link = add_query_arg( 'cpage', $cpage, $comment_link );
		}
	}

	if ( $wp_rewrite->using_permalinks() ) {
		$comment_link = user_trailingslashit( $comment_link, 'comment' );
	}

	$comment_link = $comment_link . '#comment-' . $comment->comment_ID;

	/**
	 * Filters the returned single comment permalink.
	 *
	 * @since 2.8.0
	 * @since 4.4.0 Added the `$cpage` parameter.
	 *
	 * @see get_page_of_comment()
	 *
	 * @param string     $comment_link The comment permalink with '#comment-$id' appended.
	 * @param WP_Comment $comment      The current comment object.
	 * @param array      $args         An array of arguments to override the defaults.
	 * @param int        $cpage        The calculated 'cpage' value.
	 */
	return apply_filters( 'get_comment_link', $comment_link, $comment, $args, $cpage );
}
```

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

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

## Связанные

Использует: [`get_query_var`](https://chugunov.pro/api-wordpress/functions/get_query_var/), `WP_Query`, [`user_trailingslashit`](https://chugunov.pro/api-wordpress/functions/user_trailingslashit/), `WP_Rewrite::using_permalinks`, [`get_page_of_comment`](https://chugunov.pro/api-wordpress/functions/get_page_of_comment/), [`trailingslashit`](https://chugunov.pro/api-wordpress/functions/trailingslashit/), [`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_comment`](https://chugunov.pro/api-wordpress/functions/get_comment/).
Используется в: [`wp_comments_personal_data_exporter`](https://chugunov.pro/api-wordpress/functions/wp_comments_personal_data_exporter/), `WP_REST_Comments_Controller::prepare_item_for_response`, [`_wp_dashboard_recent_comments_row`](https://chugunov.pro/api-wordpress/functions/_wp_dashboard_recent_comments_row/), [`_wp_ajax_delete_comment_response`](https://chugunov.pro/api-wordpress/functions/_wp_ajax_delete_comment_response/), `WP_Comments_List_Table::column_date`, `WP_Comments_List_Table::column_comment`, [`wp_notify_postauthor`](https://chugunov.pro/api-wordpress/functions/wp_notify_postauthor/), `WP_Widget_Recent_Comments::widget`, [`comment_link`](https://chugunov.pro/api-wordpress/functions/comment_link/), `wp_xmlrpc_server::_prepare_comment`, `Walker_Comment::comment`, `Walker_Comment::html5_comment`, [`get_comment_reply_link`](https://chugunov.pro/api-wordpress/functions/get_comment_reply_link/), [`get_comment_text`](https://chugunov.pro/api-wordpress/functions/get_comment_text/).

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