Title: Adding CSS HTML Class for Attributes Order Menu_Order
Last modified: August 22, 2016

---

# Adding CSS HTML Class for Attributes Order Menu_Order

 *  Resolved [Scott Buehler](https://wordpress.org/support/users/weborder/)
 * (@weborder)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/adding-css-html-class-for-attributes-order-menu_order/)
 * Hey guys and gals! I’ve searched high and low for this and I just can’t find 
   a solution.
 * I’m trying to find a functions.php code that will print the “Attributes” Order
   number I assign to a custom post type or page to the article HTML classes I can
   then style with CSS.
 *     ```
       <article itemtype="http://schema.org/CreativeWork" itemscope="itemscope"
       class="post-39 custom-post-type-example type-custom-post-type-example status-publish format-standard entry odd">
       ```
   
 * In the above example CPT “Custom Post Type Example” if I assign a post with Attribute
   4, I need it to add a class rank4 or similar.
 * I figured out how to **add odd/even** to this (as bolded) through searching here:
 *     ```
       //* Add Odd/Even Class to WordPress Posts
       add_filter ( 'post_class' , 'oddeven_post_class' );
       	global $current_class;
       	$current_class = 'odd';
   
       function oddeven_post_class ( $classes ) {
          global $current_class;
          $classes[] = $current_class;
          $current_class = ($current_class == 'odd') ? 'even' : 'odd';
          return $classes;
       }
       ```
   
 * Any way to add the attribute order as well? This will take my design to the next
   level. Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [Scott Buehler](https://wordpress.org/support/users/weborder/)
 * (@weborder)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/adding-css-html-class-for-attributes-order-menu_order/#post-5366794)
 * Spent another day looking for a solution to this. I take it this wouldn’t be 
   possible in a function and would require actual theme template modifications?
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/adding-css-html-class-for-attributes-order-menu_order/#post-5366862)
 * I think there’s a way. You should be able to get the menu_order attribute from
   the global $post object. Like so:
 *     ```
       global $post;
       $current_class = 'Rank'.$post->menu_order;
       ```
   
 * This only works inside the loop, which appears to be the case here.
 *  Thread Starter [Scott Buehler](https://wordpress.org/support/users/weborder/)
 * (@weborder)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/adding-css-html-class-for-attributes-order-menu_order/#post-5366899)
 * Can’t seam to get the above to work.
 * I would need a full function like my OP above to test it on my local host. I’m
   not a PHP coder unfortunately.
 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/adding-css-html-class-for-attributes-order-menu_order/#post-5366902)
 * This should work for you, assuming you don’t need the odd even bit.
 *     ```
       // Add Menu Order Rank Class to WordPress Posts
       add_filter ( 'post_class' , 'menu_rank_post_class' );
   
       function menu_rank_post_class ( $classes ) {
          global $post;
          $classes[] = 'rank-'.$post->menu_order;
          return $classes;
       }
       ```
   
 * Actually, this and your original code will work together by adding two different
   filters, independent of each other.
 *  Thread Starter [Scott Buehler](https://wordpress.org/support/users/weborder/)
 * (@weborder)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/adding-css-html-class-for-attributes-order-menu_order/#post-5366903)
 * bcworks, brilliant! It works! You were right to think I would be replacing odd/
   even with this if I could get it to work.
 * I appreciate this very much.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Adding CSS HTML Class for Attributes Order Menu_Order’ is closed to new
replies.

## Tags

 * [class](https://wordpress.org/support/topic-tag/class/)
 * [even](https://wordpress.org/support/topic-tag/even/)
 * [menu_order](https://wordpress.org/support/topic-tag/menu_order/)
 * [odd](https://wordpress.org/support/topic-tag/odd/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 5 replies
 * 2 participants
 * Last reply from: [Scott Buehler](https://wordpress.org/support/users/weborder/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/adding-css-html-class-for-attributes-order-menu_order/#post-5366903)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
