Home / css / Alternate odd even post class
  • Alternate odd even post class

    Adding this PHP code to your wordpress theme will append odd or even classes to post_class function.

    wordpress snippet : PHP

    <>
    function oddeven_post_class ( $classes ) {
       global $current_class;
       $classes[] = $current_class;
       $current_class = ($current_class == 'odd') ? 'even' : 'odd';
       return $classes;
    }
    add_filter ( 'post_class' , 'oddeven_post_class' );
    global $current_class;
    $current_class = 'odd';
    

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

    post_class, add_filter,

Build a better with wpsnipp.com

Weekly snippets, themes, deals coupons roundup.

x No Thanks