Home WordPress Comment Functions paginate_comments_links() Definition In WordPress, paginate_comments_links() prints numbered page links for the comments of a post, such as 1, 2, 3, and Next.
It works only on single posts and only when Break comments into pages is on in Settings → Discussion . It uses paginate_links() inside.
Syntax Call it with no arguments, or pass an array to change the text and the type.
paginate_comments_links();
paginate_comments_links( array( 'prev_text' => 'Back', 'next_text' => 'Forward' ) ); Call What it does paginate_comments_links()Prints the page links with default text. paginate_comments_links( array( 'prev_text' => 'Back' ) )Changes the text of the Previous link. paginate_comments_links( array( 'echo' => false ) )Returns the links instead of printing them.
The arguments are the same as for paginate_links(), for example prev_text, next_text, type, end_size, and mid_size.
Full declaration paginate_comments_links( string|array $args = array() ): void|string|array Parameters Parameter Description $argsOptional. A query string or an array of options. It accepts the options of paginate_links(), such as prev_text, next_text, type, end_size, mid_size, and echo.
Return Value Return Value Description void|string|array Prints the links by default and returns nothing. With 'echo' => false, it returns a string. With 'type' => 'array', it returns an array.
WordPress Examples Three short theme examples. Each one has a sample output.
1. Default links 2. Custom text 3. As a list Example 1 — Default links Print the numbered links under the comments.
<nav class="comment-pages">
<?php paginate_comments_links(); ?>
</nav> <nav class="comment-pages">
<span aria-current="page" class="page-numbers current">1</span>
<a class="page-numbers" href="https://example.com/hello-world/comment-page-2/#comments">2</a>
<a class="next page-numbers" href="https://example.com/hello-world/comment-page-2/#comments">Next »</a>
</nav> How It Works The visitor is on comment page 1. The current page is a span. Other pages are links. A Next link is added automatically. Example 2 — Custom text Change the Previous and Next text.
<?php
paginate_comments_links( array(
'prev_text' => 'Back',
'next_text' => 'Forward',
) );
?> <span aria-current="page" class="page-numbers current">2</span>
<a class="prev page-numbers" href="...comment-page-1/#comments">Back</a>
<a class="next page-numbers" href="...comment-page-3/#comments">Forward</a> How It Works prev_text and next_text set the labels.The visitor is on comment page 2. Page number links are still printed. Example 3 — As a list Print the page links as an unordered list.
<?php paginate_comments_links( array( 'type' => 'list' ) ); ?> <ul class='page-numbers'>
<li><span aria-current="page" class="page-numbers current">1</span></li>
<li><a class="page-numbers" href="...comment-page-2/#comments">2</a></li>
<li><a class="next page-numbers" href="...comment-page-2/#comments">Next »</a></li>
</ul> How It Works type set to list makes a ul.Each link is inside an li. Lists are easy to style with CSS. Frequently Asked Questions What does paginate_comments_links() do? It prints numbered page links for the comments of a post.
Why are no links printed? Comment paging may be off, there may be only one page of comments, or you are not on a single post.
How do I change the Previous and Next text? Pass prev_text and next_text in the arguments array.
How do I get the links as a string? Pass 'echo' => false.
What are the simpler functions? previous_comments_link() and next_comments_link() print one link each.
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.
10 people found this page helpful
Helpful Share Copy link Suggestion