Title: Creating separate div classes for elements in an array?
Last modified: September 27, 2016

---

# Creating separate div classes for elements in an array?

 *  Resolved [kosmicbird](https://wordpress.org/support/users/kosmicbird/)
 * (@kosmicbird)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/creating-separate-div-classes-for-elements-in-an-array/)
 * I have an array of elements which are basically just 3 buttons. Button 1 takes
   users to their inbox. Button 2 takes users to page where they can create a new
   message. Button 3 takes users to the settings page.
 * The problem is I need to be able to apply a different CSS style to each button,
   but there is only one overarching class assigned to all 3 buttons which is something
   like div#button-menu. So I can’t target each individual button, I can only target
   the div as a whole.
 * Here is the code that (I think) I need to modify somehow to create separate divs.
   Not really sure what to do though.
 *     ```
       private function get_menu()
       	{
       		$menu = array(
       				'newmessage'	=> array(
       					'title'			=> __('New Message', 'front-end-pm'),
       					'action'			=> 'newmessage',
       					'priority'			=> 10
       					),
       				'message_box'	=> array(
       					'title'			=> sprintf(__('Inbox%s', 'front-end-pm'), fep_get_new_message_button() ),
       					'action'			=> 'messagebox',
       					'priority'			=> 5
       					),
       				'settings'	=> array(
       					'title'			=> __('Settings', 'front-end-pm'),
       					'action'			=> 'settings',
       					'priority'			=> 15
       					),
   
       				);
       		if( ! fep_current_user_can( 'send_new_message' ) ) {
       			unset($menu['newmessage']);
       		}
   
       		$menu = apply_filters('fep_menu_buttons', $menu );
   
       				foreach ( $menu as $key => $tab )
       					{
   
       						$defaults = array(
       								'title'			=> '',
       								'action'		=> $key,
       								'class'			=> 'fep-button',
       								'active-class'	=> 'fep-button-active',
       								'priority'		=> 20
       							);
       					$menu[$key] = wp_parse_args( $menu[$key], $defaults);
   
       				}
       			uasort( $menu, 'fep_sort_by_priority' );
   
       		return $menu;
       	}
   
        }
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [kosmicbird](https://wordpress.org/support/users/kosmicbird/)
 * (@kosmicbird)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/creating-separate-div-classes-for-elements-in-an-array/#post-8227370)
 * Oh yea! Figured it out. The answer was in my face the whole time! For anyone 
   having this issue in the future:
 * I needed to add a line of code within each array button like this:
 * `'class' => 'newmessage-button'`
 * So my final code ended up looking like this:
 *     ```
       private function get_menu()
       	{
       		$menu = array(
       				'newmessage'	=> array(
       					'title'			=> __('New Message', 'front-end-pm'),
       					'action'			=> 'newmessage',
                         			'class'		        	=> 'newmessage-button',
                                             'priority'			=> 10
       					),
       				'message_box'	=> array(
       					'title'			=> sprintf(__('Inbox%s', 'front-end-pm'), fep_get_new_message_button() ),
       					'action'			=> 'messagebox',
       					'class'		        	=> 'inbox-button',
                                               'priority'			=> 5
       					),
       				'settings'	=> array(
       					'title'			=> __('Settings', 'front-end-pm'),
       					'action'			=> 'settings',
       					'class'		         	=> 'settings-button',
                                               'priority'			=> 15
       					),
   
       				);
       		if( ! fep_current_user_can( 'send_new_message' ) ) {
       			unset($menu['newmessage']);
       		}
   
       		$menu = apply_filters('fep_menu_buttons', $menu );
   
       				foreach ( $menu as $key => $tab )
       					{
   
       						$defaults = array(
       								'title'			=> '',
       								'action'		=> $key,
       								'class'			=> 'fep-button',
       								'active-class'	=> 'fep-button-active',
       								'priority'		=> 20
       							);
       					$menu[$key] = wp_parse_args( $menu[$key], $defaults);
   
       				}
       			uasort( $menu, 'fep_sort_by_priority' );
   
       		return $menu;
       	}
   
        } 
       ```
   
 * So simple, didn’t even need to create any divs.
    -  This reply was modified 9 years, 8 months ago by [kosmicbird](https://wordpress.org/support/users/kosmicbird/).
    -  This reply was modified 9 years, 8 months ago by [kosmicbird](https://wordpress.org/support/users/kosmicbird/).

Viewing 1 replies (of 1 total)

The topic ‘Creating separate div classes for elements in an array?’ is closed to
new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [kosmicbird](https://wordpress.org/support/users/kosmicbird/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/creating-separate-div-classes-for-elements-in-an-array/#post-8227370)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
