Using WordPress ‘previous_comments_link()’ PHP function

The previous_comments_link() WordPress PHP function displays the link to the previous comments page.

Usage

To use the function, simply call it in your theme’s comments template:

previous_comments_link( 'Older Comments' );

Parameters

  • $label (string) Optional: Label for comments link text. Default: ”

More information

See WordPress Developer Resources: previous_comments_link

Examples

Basic usage

Display a simple “Older Comments” link.

// Display "Older Comments" link
previous_comments_link( 'Older Comments' );

Adding a custom class

Add a custom class to the “Older Comments” link for styling purposes.

// Display "Older Comments" link with a custom class
previous_comments_link( '<span class="custom-class">Older Comments</span>' );

Using Font Awesome icon

Add a Font Awesome icon to the “Older Comments” link.

// Display "Older Comments" link with a Font Awesome icon
previous_comments_link( '<i class="fas fa-arrow-left"></i> Older Comments' );

Wrap the “Older Comments” link in a custom div container.

// Display "Older Comments" link in a custom div container
echo '<div class="older-comments-link-container">';
previous_comments_link( 'Older Comments' );
echo '</div>';

Adding a conditional check

Check if there are previous comments pages and display the “Older Comments” link only if true.

// Check if there are previous comments pages
if ( get_previous_comments_link() ) {
    // Display "Older Comments" link
    previous_comments_link( 'Older Comments' );
}