Sunday, July 7, 2013

How to Add class to links generated by next_posts_link and previous_posts_link functions in WordPress

next_posts_link and previous_posts_link functions create anchor links, and you can customize a lot of it, but it's impossible to add a class through just using their parameters alone. Add code below to functions.php file of your template:

add_filter('next_posts_link_attributes', 'posts_link_attributes_1');
add_filter('previous_posts_link_attributes', 'posts_link_attributes_2');

function posts_link_attributes_1() {
return 'class="prev-post"';
}
function posts_link_attributes_2() {
return 'class="next-post"';
}


Disqus Comments