Title: Custom Menu Classes
Last modified: August 20, 2016

---

# Custom Menu Classes

 *  [imrandyk](https://wordpress.org/support/users/imrandyk/)
 * (@imrandyk)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/custom-menu-classes/)
 * I’m trying to add a custom class to the menus that are generated. I am adding
   a custom field to each page/post and I need the value to be in the class. Here
   is my code.
 *     ```
       add_filter('nav_menu_css_class' , 'special_nav_class' , 10 , 2);
       	function special_nav_class($classes, $item){
       		$color = get_post_custom($item->object_id, 'color', TRUE);
       		echo "[".$item->object_id."][".$color."]";
       		if($color == "green"){
       			$classes[] = 'green';
       		}else if($color == "yellow"){
       			$classes[] = 'yellow';
       		}else{
       			$classes[] = 'pink';
       		}
       		return $classes;
       	}
       ```
   
 * The part the does the echo is spitting out the correct ID but the $color is always
   an array. I can’t figure out what is going wrong.

Viewing 1 replies (of 1 total)

 *  [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * (@big-bagel)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/custom-menu-classes/#post-2409103)
 * `get_post_custom` only takes one argument and always returns an array.
 * [Function Reference/get post custom](http://codex.wordpress.org/Function_Reference/get_post_custom)
 * I think you’re looking for `get_post_meta`:
 *     ```
       $color = get_post_meta( $item->object_id, 'color', true );
       ```
   
 * [Function Reference/get post meta](http://codex.wordpress.org/Function_Reference/get_post_meta)

Viewing 1 replies (of 1 total)

The topic ‘Custom Menu Classes’ is closed to new replies.

## Tags

 * [classes](https://wordpress.org/support/topic-tag/classes/)
 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [Big Bagel](https://wordpress.org/support/users/big-bagel/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/custom-menu-classes/#post-2409103)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
