WordPress comments_link() Function

Beginner
3 min read
Updated: Nov 2026
3 examples
Template tag

Definition

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.

Syntax

It takes no useful arguments. Both parameters are no longer used.

WordPress
comments_link();
<a href="<?php comments_link(); ?>">Comments</a>
CallWhat 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.

Full declaration
WordPress
comments_link( string $deprecated = '', string $deprecated_2 = '' ): void

Parameters

ParameterDescription
$deprecatedNot used. Do not pass a value.
$deprecated_2Not used. Do not pass a value.

Return Value

Return ValueDescription
voidNothing is returned. The function prints the URL.

WordPress Examples

Three short theme examples. Each one has a sample output.

Example 1 — In a link

Link to the comments of each post.

WordPress
<a href="<?php comments_link(); ?>">Jump to comments</a>

How It Works

  1. comments_link() prints the URL.
  2. It is placed inside href.
  3. The link jumps to the element with the id comments.

Example 2 — With a count

Show the number of comments in the link text.

WordPress
<a href="<?php comments_link(); ?>"><?php comments_number(); ?></a>

How It Works

  1. comments_link() prints the address.
  2. comments_number() prints the count text.
  3. Together they make a link such as 3 Comments.

Example 3 — Return value

Use get_comments_link() in PHP.

WordPress
<?php $url = get_comments_link(); ?>
<a href="<?php echo esc_url( $url ); ?>">Comments</a>

How It Works

  1. get_comments_link() returns the URL.
  2. esc_url() makes it safe for href.
  3. Use this to change the URL before you print it.

Frequently Asked Questions

The URL of the comments area of the current post, ending with #comments.
No. It prints only the URL.
In the post loop, for example in archive or single templates.
Use get_comments_link().
Use comments_popup_link().

Next: comments_number()

Print the number of comments of a post as text.

comments_number() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful