get_the_comments_navigation()
Gets links to the previous/next comment pages, if such links exist. Used on post pages in the comments block.
If the result of this function needs to be displayed immediately, use the_comments_navigation()
No Hooks.
Returns
String. Ready HTML code of the pagination block for comments.
Usage
get_the_comments_navigation( $args );
- $args(array)
Parameters of the output block as an array. Can be:
-
prev_text(string)
Text of the anchor link for previous comments.
Default: "Previous comments" -
next_text(string)
Text of the anchor link for next comments.
Default: "Next comments" -
screen_reader_text(string)
Text for robots reading the code. Used for the navigation block.
Default "Comment navigation" -
aria_label(string) (WP 5.5)
Value of the attributearea-label=""for <nav> element.
Default: __( 'Posts' ) - class(string) (WP 5.5)
Value of the attributeclass=""for <nav> element.
Default: 'post-navigation'
Default: array()
-
Examples
#1 Demo
Suppose the post has 44 comments and we are on the second page of the comment pagination, then:
$html = get_the_comments_navigation();
$html will contain:
<nav class="navigation comment-navigation" role="navigation"> <h2 class="screen-reader-text">Comments Navigation</h2> <div class="nav-links"> <div class="nav-previous"> <a href="http://example.com/foo/comment-page-1#comments">Previous comments</a> </div> <div class="nav-next"> <a href="http://example.com/foo/comment-page-3#comments">Next comments</a> </div> </div> </nav>
Changelog
| Since 4.4.0 | Introduced. |
| Since 5.3.0 | Added the aria_label parameter. |
| Since 5.5.0 | Added the class parameter. |