WP append odd & even class to WordPress body_class


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. //append odd/even classes to post_class function
  2. function oddeven_post_class ( $classes ) {
  3. global $current_class;
  4. $classes[] = $current_class;
  5.  
  6. $current_class = ($current_class == 'odd') ? 'even' : 'odd';
  7.  
  8. return $classes;
  9. }
  10. add_filter ( 'post_class' , 'oddeven_post_class' );
  11. global $current_class;
  12. $current_class = 'odd';

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.