Posted by & filed under WordPress.

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.

function add_class_next_post_link($html){
    $html = str_replace('<a','<a class="next"',$html);
    return $html;
function add_class_previous_post_link($html){
    $html = str_replace('<a','<a class="prev"',$html);
    return $html;

Leave a Reply

Your email address will not be published. Required fields are marked *