The get_previous_comments_link WordPress PHP function retrieves the link to the previous comments page.
Usage
get_previous_comments_link($label);
Example:
echo get_previous_comments_link('View previous comments');
Parameters
$label
string (Optional): Label for comments link text. Default: ”
More information
See WordPress Developer Resources: get_previous_comments_link
Examples
Display a link to the previous comments page
This code displays a link to the previous comments page with custom text.
if (get_previous_comments_link()) { echo '<div class="previous-comments">'; echo get_previous_comments_link('View previous comments'); echo '</div>'; }
Custom styling for the previous comments link
Add a custom class to style the previous comments link.
if (get_previous_comments_link()) { echo '<div class="previous-comments">'; echo get_previous_comments_link('<span class="custom-link">Previous Comments</span>'); echo '</div>'; }
Conditional display based on the number of comments pages
Only show the previous comments link if there are more than two comments pages.
if (get_comment_pages_count() > 2 && get_previous_comments_link()) { echo '<div class="previous-comments">'; echo get_previous_comments_link('Go to previous comments page'); echo '</div>'; }
Adding an icon to the previous comments link
Add an icon to the previous comments link using Font Awesome.
if (get_previous_comments_link()) { echo '<div class="previous-comments">'; echo get_previous_comments_link('<i class="fas fa-chevron-left"></i> Previous Comments'); echo '</div>'; }
Display previous comments link with a custom HTML structure
Create a custom HTML structure for the previous comments link.
if (get_previous_comments_link()) { echo '<div class="nav-previous">'; echo '<span class="meta-nav">←</span> '; echo get_previous_comments_link('Older Comments'); echo '</div>'; }