Example 1 — In a link
Link to the comments of each post.
<a href="<?php comments_link(); ?>">Jump to comments</a> How It Works
comments_link()prints the URL.- It is placed inside
href. - The link jumps to the element with the id
comments.

In WordPress, comments_link() prints the URL of the comments section of the current post. It ends with #comments.
It prints only the address. You write the a tag yourself. Use it in the post loop, not in the comment loop.
It takes no useful arguments. Both parameters are no longer used.
comments_link();
<a href="<?php comments_link(); ?>">Comments</a> | Call | What it does |
|---|---|
comments_link() | Prints the URL of the comments area. |
get_comments_link() | Returns the URL instead of printing it. |
comments_popup_link() | Prints a full link with the comment count. |
The function runs esc_url() for you, so you do not need to escape the output again.
comments_link( string $deprecated = '', string $deprecated_2 = '' ): void | Parameter | Description |
|---|---|
$deprecated | Not used. Do not pass a value. |
$deprecated_2 | Not used. Do not pass a value. |
| Return Value | Description |
|---|---|
| void | Nothing is returned. The function prints the URL. |
Three short theme examples. Each one has a sample output.
Link to the comments of each post.
<a href="<?php comments_link(); ?>">Jump to comments</a> comments_link() prints the URL.href.comments.Show the number of comments in the link text.
<a href="<?php comments_link(); ?>"><?php comments_number(); ?></a> comments_link() prints the address.comments_number() prints the count text.Use get_comments_link() in PHP.
<?php $url = get_comments_link(); ?>
<a href="<?php echo esc_url( $url ); ?>">Comments</a> get_comments_link() returns the URL.esc_url() makes it safe for href.Print the number of comments of a post as text.
13 people found this page helpful