You can use a Custom Walker to add attributes to the menu items.
Basically, you add a parameter ‘walker’ to the wp_nav_menu() options and call an instance of an enhanced class:
wp_nav_menu(
array (
'menu' => 'main-menu',
'container' => FALSE,
'container_id' => FALSE,
'menu_class' => '',
'menu_id' => FALSE,
'depth' => 1,
'walker' => new Description_Walker
)
);
The class Description_Walker
extends Walker_Nav_Menu
and changes the function start_el( &$output, $item, $depth, $args )
.
-
From the Codex:
http://codex.wordpress.org/Function_Reference/wp_nav_menu#Using_a_Custom_Walker_Function -
I found this tutorial, you might find it very useful:
http://www.kriesi.at/archives/improve-your-wordpress-navigation-menu-output
Related Posts:
- Adding first / last CSS classes to menus
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- Menu Custom Data Attributes
- How to modify mobile nav menu text in theme
- Extend Menu Walker Output
- conditional: if is page, and all subpages
- wp nav menu: show submenu below li item
- Styling an “active” link outside of WordPress default menu
- how to changes mobile menu toggle breakpoint in WordPress
- How to make only the valid active page of a multilevel menu active with – “.nav li.current-menu-item a”?
- dynamic php menu with hidden sub-categories only showing when the category name is clicked
- How to let mobile navigation menu close when link is clicked?
- Bring Font Awesome icons inside menu A tags
- Display specific main Sub Nav on Woocommerce product pages
- How limit the width of a fixed menu-bar on scroll?
- WP_Nav Highlight Parent Issue
- How to change the menu color
- Hide main div if wp_nav_menu is empty
- How to remove a metabox from menu editor page?
- How to change “Shipping Calculator “field label on Cart Page – woocommerce? [closed]
- How to create different menu’s for not logged in visitors and for logged in members?
- How to add active class to custom menu using while loop and wp_list_pages
- How to place login logout link on menu that redirects users back to current page?
- Theme Customizer – Dynamic CSS PHP File
- WordPress doesn’t include css
- Understanding child theme functions.php
- Unusable menus and “Illegal widget setting ID: nav_menu_item[]” error
- Want to create Child theme, but already edited Parent theme css files and some php files
- Style every second widget?
- Change Navigation Bar based on logged in or not
- Plugin CSS not enqueing
- How can I Add a variable PHP in the Menu Nav
- Where to place PHP code that inserts (or doesn’t insert) menu item?
- Adding an Avatar to the Top Nav Bar
- How to design a table based on css values set from admin/dashboard
- Unique icons next to each WordPress menu item
- Best way to schedule daily change in CSS parameter
- Auto 301 to full post permalink? (using : /archive/%post_id% to %post_name% )
- Whats the proper way to use a php stylesheet in a wordpress theme? [duplicate]
- How do I add a custom css to all posts without affecting homepage css? [closed]
- Automatically set all tags to have a height of 0 if there is no content inside the tag [closed]
- height should be set to auto to avoid pixelation in the post thumbnail function
- Correct way to enqueue page specific CSS file
- Wrapping a Sidebar within
- Show About and Contact Us page when they’re clicked in the top menu.
- Add login hyperlink to secondary navigation menu
- Clickable image link sends people to wrong URL
- Creating a blog on my companies new website using WordPress but I have sidebar issues
- Get ACF options field in PHP acting as CSS
- wp_nav_menu not working correctly in my underscores theme
- Problem with adding custom CSS class to image in ACF Photo Gallery plugin [closed]
- How to use wp_nav_menu to create custom dropdown menu?
- Get css class of menu item in custom menu structure
- Link to page with posts of specific type
- Conditionally load class in the comment section of the post page
- Assign Custom classes to every Excerpt
- Show login greeting above sub-menu links?
- How to tell if a user has gone in and created a menu
- Adding a navigation page state to individual blog and portfolio pages
- Using theme options to change a border-radius value
- Inline CSS header style priority function.php Child (no enqueing I think)
- Displaying images outside the content
- Add class to ul and li in wp_na
- How to put search bar & logo in the “primary navigation” storefront theme?
- Applying css in functions.php
- Providin exception to WordPress wp_nav_menu Custom CSS Classes
- PHP function for horizontal Woocommerce thumbnails and badges
- My top header looks different on single pages but is fine on the home page
- Using php code inside style tag
- Warning: Use of undefined constant all – assumed ‘all’ (this will throw an Error in a future version of PHP) in C:\Users\…….. on line 6
- Drop down question
- How to print all the inline styles in the WP_Styles instance together with their keys?
- The style.php file inside theme-engine folder has other content on FTP
- how to add functions to my function.php using a child theme?
- Replace header with large image on home page only, using Genesis child theme
- Site title not showing. Please help me
- PHP/CSS: Shortcode won’t display correctly, and only displays in the head (before content)
- Hot to edit WooCOmmerce dashboard?
- Using Sprit-sheet on WordPress categories
- Add class for the_post_thumbnail_caption()
- Target a specific container to style on WordPress storefront theme
- How to list categories by page id in wordpress
- Custom Theme, Editor won’t wrap text (i.e. change width)
- Click to expand menu
- How to add style in functions.php depending on conditions?
- wp_nav_menu doesn’t work in a duplicate server
- How I can add div to menu?
- Hide button based on PHP result
- Using ‘array’ method in wp_nav_menu causes it to disappear
- Child theme not working properly
- WordPress – Image href for home menu nav not working
- if is_home(), change class of menu-item-225 of wp_nav_menu
- Change order that the menu is generated with wp_list_pages
- I am extending Walker_Nav_Menu: How can I get the number of children elements of the current item?
- How to change a specific character in a theme option value – replace a space with a plus sign
- How do I modify the with wp_nav_menu()
- New to wordpress. Need Help with templates [closed]
- Child-theme suddenly stopped working [closed]
- Parse error: syntax error, unexpected ‘}’ in
- ‘This Field is Required.’ is Not Displaying on CF7 [closed]