SDAC Blog

Read our latest blog posts, learn something new, find answers, and stay up to date.

HOWTO: Add Custom Classes to Post Navigation Links

Sometimes you just need to have a bit more control over the display of the post navigation (next_posts_link, previous_posts_link). You can easily add in your own custom classes by adding the code below to your theme’s functions.php file. In the example below – I added in a custom class “older” and “newer”. You can add in anything there you would like.

add_filter('next_posts_link_attributes', 'sdac_next_posts_link_attributes');
function sdac_next_posts_link_attributes(){
		return 'class="older"';
}

add_filter('previous_posts_link_attributes', 'sdac_previous_posts_link_attributes');
function sdac_previous_posts_link_attributes(){
		return 'class="newer"';
}