Function and usage of paginate_comments_links() in wordpress


Answers ( 1 )


    The paginate_comments_links() function in WordPress is used to display or retrieve pagination links for the comments on the current post. This function is highly customizable and allows for extensive control over how the pagination links are displayed. Here's a detailed explanation of its usage:

    Function Prototype

    paginate_comments_links( string|array $args = array() ): void|string|array

    Function Description

    • Purpose: To display or retrieve pagination links for comments on the current post.
    • Related Function: paginate_links(). It's advisable to see this function as well since paginate_comments_links() uses it internally and accepts most of its arguments.


    • $args (string|array): Optional. An array or string of arguments for generating paginated links for archives. The function uses these arguments:
      • base (string): Base of the paginated URL.
      • format (string): Format for the pagination structure.
      • total (int): Total amount of pages. Default is the value of WP_Query's max_num_pages or 1.
      • current (int): Current page number. Default is 'paged' query var or 1.
      • aria_current (string): Value for the aria-current attribute. Possible values include 'page', 'step', 'location', 'date', 'time', 'true', 'false'. Default is 'page'.
      • show_all (bool): Whether to show all pages. Default is false.
      • end_size (int): Number of numbers on either the start and end list edges. Default is 1.
      • mid_size (int): Number of numbers to either side of current pages. Default is 2.
      • prev_next (bool): Whether to include previous and next links. Default is true.
      • prev_text (string): Text for the previous page. Default is ‘« Previous’.
      • next_text (string): Text for the next page. Default is ‘Next »’.
      • type (string): Controls the format of the returned value. Possible values are 'plain', 'array', and 'list'. Default is 'plain'.
      • add_args (array): Array of query args to add. Default is false.
      • add_fragment (string): String to append to each link.
      • before_page_number (string): String to appear before the page number.
      • after_page_number (string): String to append after the page number.

    Return Value

    • The function returns void, a string, or an array depending on the 'echo' and 'type' arguments.
      • If 'echo' is true and 'type' is not an array, or if the query is not for an existing single post of any post type, it returns void.
      • Otherwise, it returns markup for comment page links or an array of comment page links, depending on the 'type' argument.

    Sample Usage

    Here's an example of how you might use paginate_comments_links():

    $args = array(
        'prev_text' => __('Previous Comments'),
        'next_text' => __('Next Comments'),
        'type'      => 'list',

    In this example, we're customizing the previous and next text for the comment pagination and setting the type of output to a list. This will output an HTML list of pagination links for the comments on the current post.

Leave an answer