Home / functions.php / Add class to next and previous post_link
  • Add class to next and previous post_link

    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.

    wordpress snippet : PHP

    <>
    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);
    

    ( WordPress codex functions, hooks, in this snippet. )

    post_link, add_filter, _n,
  • http://apadong.com/ ARS

    wow, that’s cool! thanks man!

    • http://wpsnipp.com Kevin Chard

      Cool glad to see you like the snippet

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks