Skip to content Skip to menu

Dzikri Aziz

The D is silent — kind of.

Add Custom Attributes to WordPress’ Posts Navigation

The Problem

We need to add our custom class(es) to the posts navigation links to be able to add some styles.

The Solution

Use the available next_posts_link_attributes and previous_posts_link_attributes hooks.


Open your theme’s function.php file and add these lines (must be inside the <?php ?> tag):

add_filter( 'next_posts_link_attributes', 'kc_next_post_link_attr' );
add_filter( 'previous_posts_link_attributes', 'kc_prev_post_link_attr' );

function kc_next_post_link_attr() {
	return 'class="next-page"';

function kc_prev_post_link_attr() {
	return 'class="prev-page"';

Posted on in Tips & Tutorials.