Using WordPress ‘get_the_comments_pagination()’ PHP function

The get_the_comments_pagination() WordPress PHP function retrieves a paginated navigation to the next or previous set of comments when applicable.

Usage

echo get_the_comments_pagination( array( 'mid_size' => 2 ) );

Parameters

  • $args (array) – Optional. Default pagination arguments:
    • 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: ‘comments-pagination’.

More information

See WordPress Developer Resources: get_the_comments_pagination

Examples

Basic usage of the function

echo get_the_comments_pagination();

This will display the default comments pagination.

Customizing the screen reader text

echo get_the_comments_pagination( array( 'screen_reader_text' => 'Navigate through comments' ) );

This will display comments pagination with custom screen reader text.

Customizing the ARIA label

echo get_the_comments_pagination( array( 'aria_label' => 'Comment pages' ) );

This will display comments pagination with a custom ARIA label.

Customizing the class of the nav element

echo get_the_comments_pagination( array( 'class' => 'my-custom-pagination' ) );

This will display comments pagination with a custom class for the nav element.

Combining multiple customizations

echo get_the_comments_pagination( array(
  'screen_reader_text' => 'Navigate through comments',
  'aria_label' => 'Comment pages',
  'class' => 'my-custom-pagination'
) );

This will display comments pagination with custom screen reader text, ARIA label, and class for the nav element.