The get_the_comments_navigation() WordPress PHP function retrieves navigation to the next/previous set of comments, when applicable.
Usage
echo get_the_comments_navigation( array( 'prev_text' => 'Previous Comments', 'next_text' => 'Next Comments' ));
Parameters
$args
(array) – Optional. Default comments navigation arguments:prev_text
(string) – Anchor text to display in the previous comments link. Default ‘Older comments’.next_text
(string) – Anchor text to display in the next comments link. Default ‘Newer comments’.screen_reader_text
(string) – Screen reader text for the nav element. Default ‘Comments navigation’.aria_label
(string) – ARIA label text for the nav element. Default ‘Comments’.class
(string) – Custom class for the nav element. Default ‘comment-navigation’.
More information
See WordPress Developer Resources: get_the_comments_navigation()
Examples
Basic usage
Display the default comments navigation.
echo get_the_comments_navigation();
Custom text for previous and next links
Display comments navigation with custom text for previous and next links.
echo get_the_comments_navigation( array( 'prev_text' => 'Go to previous comments', 'next_text' => 'Go to next comments' ));
Custom screen reader text
Change the screen reader text for better accessibility.
echo get_the_comments_navigation( array( 'screen_reader_text' => 'Navigate through the comments' ));
Custom ARIA label and class
Add a custom ARIA label and class to the nav element.
echo get_the_comments_navigation( array( 'aria_label' => 'Comment Navigation', 'class' => 'my-custom-comment-navigation' ));
Combining all customizations
Combine all customizations for the comments navigation.
echo get_the_comments_navigation( array( 'prev_text' => 'Previous Comments', 'next_text' => 'Next Comments', 'screen_reader_text' => 'Navigate through the comments', 'aria_label' => 'Comment Navigation', 'class' => 'my-custom-comment-navigation' ));