
Definition
In WordPress, comments_popup_link() prints a link to the comments of the current post. The link text shows the number of comments.
If there are no comments, the link goes to the comment form (#respond). If comments are closed, it prints plain text instead of a link.
Syntax
Call it with no arguments for the defaults, or set the texts and a CSS class.
comments_popup_link();
comments_popup_link( 'Leave a comment', '1 Comment', '% Comments', 'comments-link', 'Comments are off' );
| Call | What it does |
|---|
comments_popup_link() | Prints a link with default texts. |
comments_popup_link( 'Leave a comment', '1 Comment', '% Comments' ) | Prints a link with your own texts. |
comments_popup_link( '', '', '', 'comments-link' ) | Adds a CSS class to the link. |
Use it in the post loop. The word popup is old. The link does not open a popup window.
Full declaration
comments_popup_link( string|false $zero = false, string|false $one = false, string|false $more = false, string $css_class = '', string|false $none = false ): void
Parameters
| Parameter | Description |
|---|
$zero | Optional. Text when there are no comments. |
$one | Optional. Text when there is one comment. |
$more | Optional. Text when there are more comments. Use % for the number. |
$css_class | Optional. A CSS class for the link. Default is empty. |
$none | Optional. Text when comments are turned off. |
Return Value
| Return Value | Description |
|---|
| void | Nothing is returned. The function prints a link or a short text. |
WordPress Examples
Three short theme examples. Each one has a sample output.
Example 1 — Default link
Print the link with default text.
<p class="meta"><?php comments_popup_link(); ?></p>
<p class="meta"><a href="https://example.com/hello-world/#comments">3 Comments<span class="screen-reader-text"> on Hello World</span></a></p>
How It Works
- The post has three comments, so the link goes to #comments.
- The text shows the number.
- A hidden screen reader text names the post.
Example 2 — Custom text
Use your own texts for each case.
<?php comments_popup_link( 'Leave a comment', '1 Comment', '% Comments', 'comments-link', 'Comments are off' ); ?>
<a href="https://example.com/hello-world/#comments" class="comments-link" >3 Comments</a>
How It Works
- The five arguments are zero, one, more, class, and none.
- This output is for a post with three comments.
- With no comments the link goes to #respond.
Example 3 — When comments are closed
See the output when comments are off and there are none.
<?php comments_popup_link( 'Leave a comment', '1 Comment', '% Comments', 'comments-link', 'Comments are off' ); ?>
<span class="comments-link">Comments are off</span>
How It Works
- There are no comments and comments are closed.
- WordPress prints a
span with the last text. - No link is printed because there is nothing to open.
Frequently Asked Questions
It prints a link to the comments of the current post, with the comment count as text.
No. The name is old. It is a normal link.
To the comments area, or to the comment form when there are no comments.
It prints the text you set in the last argument, without a link.
comments_number() prints only text. comments_popup_link() prints a link around the text.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
15 people found this page helpful