Articles of menus

Add Caret to Menu Items with Sub-Menus in WordPress Theme

I’m working on a custom theme using wp_nav_menu(). What I want to do is add a caret to menu items that have sub-menus. For example, If my menu looks like this: Menu Item 1 Menu Item 2 Menu Item 2a Menu Item 2b Menu Item 3 I want to be able to format it like […]

Get page IDs from nav items

I am trying to get all the IDs in my navigation and convert it to a string so that I can use it with wp_query to get the pages that are only listed in the nav. The code to get the IDs: $menu_name = ‘primary’; if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ […]

Add container to nav_menu sub menu

Is there a way I can wrap a div around wp_nav_menu’s ul.sub-menu So for example the markup would go from <ul class=”menu”> <li><a href=”/”>Item 1</a></li> <li> <a href=”/”>Item 2</a> <ul class=”sub-menu”> <li><a href=”/”>Item 1</a></li> <li><a href=”/”>Item 1</a></li> </ul> </li> <li><a href=”/”>Item 1</a></li> <li><a href=”/”>Item 1</a></li> </ul> to this <ul class=”menu”> <li><a href=”/”>Item 1</a></li> <li> <a […]

Why do Custom Nav Menus generate so many classes on list items? Can I manage this somehow?

Below is an example. 3 classes attached to each item, except current item, which has 6. Can I pare this down somehow? <ul id=”menu-global-nav” class=”sf-menu”> <li id=”menu-item-63″ class=”menu-item menu-item-type-post_type current-menu-item page_item page-item-5 current_page_item menu-item-63″><a href=”#”>Home</a></li> <li id=”menu-item-30″ class=”menu-item menu-item-type-post_type menu-item-30″><a href=”#”>Services</a> <ul class=”sub-menu”> <li id=”menu-item-39″ class=”menu-item menu-item-type-post_type menu-item-39″><a href=”#”>Case Studies</a></li> <li id=”menu-item-38″ class=”menu-item menu-item-type-post_type menu-item-38″><a […]

Error “Trying to get property of non-object” with Custom Walker for wp_nav_menu

I am trying to add some ARIA related stuff to the wp_nav_menu function. I use a custom walker class for this purpose: class Walker_Nav_Menu_With_Aria extends Walker_Nav_Menu { function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat(“\t”, $depth); $output .= “\n$indent<ul class=\”sub-menu\” role=\”group\”>\n”; } function end_lvl( &$output, $depth = 0, $args […]

Add a custom walker to a menu created in a widget

I know how to add a Walker to a custom menu created by the theme (menu named primary in this example), but how can I target a menu thats created in a widget with the default wordpress custom menu widget? if ( has_nav_menu( ‘primary’ ) ) { $args = array( ‘menu’ => ‘main-menu’, ‘menu_id’ => […]

Assign a Class to the Current “Tag” for Formatting

Essentially what I am hoping to replicate is something like the “current-menu-item” class that is applied to WP Menus. My client is wanting to use Tags as a sub-nav, and I’ve managed to get the tags for the category output as an unordered list, but now if someone selects the tag “Tag One”, I’d like […]

Adding category ID or slug to WP Nav Menu

Is it possible to add the id or slug of a category in the output of wp_nav_menu menu’s? For example, the standard output of wp_nav_menu is: <div class=”menu-header”> <ul id=”menu-categorieen” class=”menu”> <li id=”menu-item-4353″ class=”menu-item menu-item-type-custom menu-item-object-custom current-menu-item current_page_item menu-item-home menu-item-4353″><a href=”http://domain/”>Home</a></li> <li id=”menu-item-1034″ class=”menu-item menu-item-type-taxonomy menu-item-object-category menu-item-1034″><a href=”http://domain/category/category_1/”>Category 1</a></li> <li id=”menu-item-1039″ class=”menu-item menu-item-type-taxonomy menu-item-object-category menu-item-1039″><a […]

Add Javascript to WordPress Menu

Is there a way to put javascript in the URL portion of a WordPress menu item? I have a live chat function on my site, and I am supposed to put this code onto the site to make a link to open the live chat (as suggested here). <!– BEGIN OLARK CHAT LINK –> <a […]

wp_nav_menu: show menu only if one exists, otherwise show nothing

I’m trying to use wp_nav_menu to only display a menu if one exists, otherwise, display nothing. If I delete the menu, it will output a list of the pages. My functions.php file contains: if (function_exists(‘register_nav_menus’)) { register_nav_menus ( array(‘main_nav’ => ‘Main Navigation Menu’));} How can I use wp_nav_menu to only display a menu if one […]