X

Add class to next and previous post_link

I recently needed to use this for a theme I was building figured I would post the results up here for everyone. Adding this snippet to the functions.php of your wordpress theme will add a custom class to next and previous post_link.



Code Snippet:


function add_class_next_post_link($html){
$html = str_replace('<a','<a class="next"',$html);
return $html;
}
add_filter('next_post_link','add_class_next_post_link',10,1);

function add_class_previous_post_link($html){
$html = str_replace('<a','<a class="prev"',$html);
return $html;
}
add_filter('previous_post_link','add_class_previous_post_link',10,1);

Comments  Leave a Reply

  1. wow, that’s cool! thanks man!

    1. Cool glad to see you like the snippet

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!