Title: get_edit_comment_link
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_edit_comment_link( int|WP_Comment $comment_id, string $context ): string|void

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#wp--skip-link--target)

Retrieves the edit comment link.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#parameters)󠁿

 `$comment_id`int|[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)
optional

Comment ID or [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)
object.

`$context`stringoptional

Context in which the URL should be used. Either `'display'`, to include HTML entities,
or `'url'`. Default `'display'`.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#return)󠁿

 string|void The edit comment link URL for the given comment, or void if the comment
id does not exist or the current user is not allowed to edit it.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#source)󠁿

    ```php
    function get_edit_comment_link( $comment_id = 0, $context = 'display' ) {
    	$comment = get_comment( $comment_id );

    	if ( ! is_object( $comment ) || ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
    		return;
    	}

    	if ( 'display' === $context ) {
    		$action = 'comment.php?action=editcomment&amp;c=';
    	} else {
    		$action = 'comment.php?action=editcomment&c=';
    	}

    	$location = admin_url( $action ) . $comment->comment_ID;

    	// Ensure the $comment_id variable passed to the filter is always an ID.
    	$comment_id = (int) $comment->comment_ID;

    	/**
    	 * Filters the comment edit link.
    	 *
    	 * @since 2.3.0
    	 * @since 6.7.0 The $comment_id and $context parameters are now being passed to the filter.
    	 *
    	 * @param string $location   The edit link.
    	 * @param int    $comment_id Unique ID of the comment to generate an edit link.
    	 * @param string $context    Context to include HTML entities in link. Default 'display'.
    	 */
    	return apply_filters( 'get_edit_comment_link', $location, $comment_id, $context );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/link-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/link-template.php#L1606)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/link-template.php#L1606-L1635)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#hooks)󠁿

 [apply_filters( ‘get_edit_comment_link’, string $location, int $comment_id, string $context )](https://developer.wordpress.org/reference/hooks/get_edit_comment_link/)

Filters the comment edit link.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#related)󠁿

| Uses | Description | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [admin_url()](https://developer.wordpress.org/reference/functions/admin_url/)`wp-includes/link-template.php` |

Retrieves the URL to the admin area for the current site.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_comment()](https://developer.wordpress.org/reference/functions/get_comment/)`wp-includes/comment.php` |

Retrieves comment data given a comment ID or comment object.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#)

| Used by | Description | 
| [edit_comment_link()](https://developer.wordpress.org/reference/functions/edit_comment_link/)`wp-includes/link-template.php` |

Displays the edit comment link with formatting.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_edit_comment_link/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.7.0](https://developer.wordpress.org/reference/since/6.7.0/) | The $context parameter was added. | 
| [2.3.0](https://developer.wordpress.org/reference/since/2.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_edit_comment_link%2F)
before being able to contribute a note or feedback.