[WordPress] Add class to links generated by next_posts_link and previous_posts_link

Updated on     Kisan Patel

Problem:

How to Add class or any attribute to links generated by next_posts_link and previous_posts_link in wordpress?
wordpress add class to next_post_link

Solution:
Just add below line of code into functions.php file and replace class="button-style-class".

add_filter('next_post_link', 'boot_post_link_attributes');
add_filter('previous_post_link', 'boot_post_link_attributes');

function boot_post_link_attributes($output) {
    $code = 'class="button-style-class"';
    return str_replace('<a href=', '<a '.$code.' href=', $output);
}

Wordpress