How to display different submenus?

It is ok to put other elements as child elements. I don’t see any problem with this. To add custom elements you have to add custom metabox to menu administration. WordPress will handle saving your custom elements automatically so you don’t need to worry about this. To display your custom elements you can create custom …

Read more

Disable parent in wp_list_pages – WordPress

You can use get_pages() instead and write some custom code like this : $args = array(‘exclude’ => ‘5’, ‘sort_column’ => ‘ID’ ) $pages = get_pages($args); foreach ( $pages as $page ) { echo $page->post_title; } You may of course elaborate more the code in order to obtain a tree. You may also check the source …

Read more

Issue with plugin sub menu and pages

Your code has a syntax error, extra close-curly in new_menu(). Your test_sub_menu() function has all the vars that are used in new_menu() – but they’re not global or called to from new_menu(), so they do nothing and the functions do nothing but return undefined errors. $parent_slug = ‘new-menu’; should be instead, for a subpage, the …

Read more

How do I enable “metaboxes” by default in menu editor?

The initial nav menu metaboxes are $initial_meta_boxes = array( ‘add-post-type-page’, ‘add-post-type-post’, ‘add-custom-links’, ‘add-category’ ); They register after first time user enter the menus section. So you can register them first after you create a new user. The function wp_initial_nav_menu_meta_boxes() is setting the user_option metaboxhidden_nav-menus with array of the hidden metaboxes. And if the user_option already …

Read more

My navigation menu isn’t working. What happened? Please help!

The wrapper element has a higher priority than your menu (position relative) and lies over your menu element. Two solutions: 1) Remove the negative “top” value from the .wrapper element in css -> top: -66px; and add less padding-top instead. 2) Add a z-index value to your navigation element, for example z-index: 10

Add custom class to li element which has children

Please take a look at this walker class (Bootstrap Nav Walker) you’ll get a good understanding of how things work inside a walker. There is a has_children property in $args argument $args->has_children. You can use this to check if the current item has any children or not like the following code if ( $args->has_children ) …

Read more

Menu Custom Data Attributes

If you want to add a custom data attributes to the menu that’s generated by wp_nav_menu function. You can use the nav_menu_link_attributes filter to add the desired attributes to the <a> elements. function add_menu_atts( $atts, $item, $args ) { $atts[‘data-hover’] = $atts[‘title’]; // add data-hover attribute return $atts; } add_filter( ‘nav_menu_link_attributes’, ‘add_menu_atts’, 10, 3 );

Dropdown menu for categories

This will give you your desired result. <?php $list_categories = get_categories( $args ); echo “<div class=”container”>”; echo “<div class=”productsubmenu”>”; echo “<ul>”; foreach ($list_categories as $cat) { if($cat->category_parent == 0) { $category_id = $cat->term_id; echo ‘<li class=”parent ‘.$my.’ “><a href=”‘.get_term_link( $cat ) . ‘”>’.$cat->name.'</a>’; $args2 = array( ‘taxonomy’ => $taxonomy, ‘child_of’ => 0, ‘parent’ => $category_id, …

Read more