How to Hide Comment Pagination in WordPress

Home » Snippets » How to Hide Comment Pagination in WordPress

Created with:



Creator: WPTurbo Team

Customize with WPTurbo AI

Add Snippet To Project

New Project
Add To Existing Project

If you’re someone who feels like comment pagination on your WordPress site is taking up too much space or cluttering your comment section, you’re not alone. While comment pagination does serve a useful purpose by breaking up large comment threads, sometimes it’s just not necessary or desirable. In this article, we’ll show you how to hide comment pagination on your WordPress site.

					function wpturbo_hide_comment_pagination($defaults) {
    if (!is_admin()) {
        $defaults['page'] = '';
        $defaults['per_page'] = '';
    return $defaults;
add_filter('comments_template_query_args', 'wpturbo_hide_comment_pagination');

The code snippet is used to hide the comment pagination on WordPress pages. Pagination is typically used to display a large number of comments in smaller segments, making them easier to navigate. However, in some cases, the pagination may not be necessary, such as when there are only a few comments present.

The wpturbo_hide_comment_pagination() function takes an array of arguments, $defaults, as input. It checks whether the current request is being made from the admin panel. If it is not, it sets two values in the $defaults array to empty strings: 'page' and 'per_page'.

This action removes the pagination from the comment view. If the request is coming from the admin panel, the function returns the $defaults array unchanged, preserving the pagination.

The add_filter() function is used to apply the wpturbo_hide_comment_pagination() function to WordPress’s comments_template_query_args filter hook. This applies the function’s filter to its specified hook, which triggers the function and makes the necessary modifications to the defaults array, removing any pagination that is present on comments.

Overall, the code snippet is a simple and effective way to remove comment pagination in WordPress. By removing it, you can help create a cleaner and more streamlined interface for your users.

Register an account to save your snippets or go Pro to get more features.