Hide The Comment Pagination

Ever since version 2.7 WordPress offers the option to adjust the number of comments on each page. From SEO's perspective, this is not very smart, as there were many articles and discussions about this topic in the past. If you turn off the comment pagination, the empty HTML fragment is still in the source code of the page.

Unfortunately, the classes that respond with CSS are the same as those from the normal page and post pagination.
If you have a theme in which the outer container of pagination has a frame or a background color, then you can see the empty container. Here are 2 screenshots with and without activated comment pagination to illustrate what I mean:

Comment Pagination
Empty Comment Pagination

Another annoyance would be if .pagination has a margin-bottom, which would also have a negative effect on the layout. What can you do about it?

WordPress stores the setting of the comment pagination in the database table options under page_comments. Value 1 means on, value 0 means off. By doing so you can hide the pagination in comments.php if it is not turned on:

<?php if ((int) get_option('page_comments') === 1): ?>
	<div class="navigation">
		<div class="alignleft"><?php previous_comments_link() ?></div>
		<div class="alignright"><?php next_comments_link() ?></div>
	</div>
<?php endif; ?>

The query checks whether the comment pagination is set to (1) and displays the navigation. If it is set to (0) it will not display the navigation. On the other hand, if it is turned off, WordPress doesn't need to execute the two functions previous_comments_link() and next_comments_link().

Comments are closed.

2 comments

  1. Josh

    This is is all well and good, but what if pagination is turned on but there aren't enough comments for there to be multiple pages?

  2. Michael

    Than you have the empty html fragment in your site.