Show parent categories and sub categories but not grand children categories

In the single post you can get the parent category like this $category = wp_get_object_terms(get_the_ID(), ‘category’, array(‘parent’=>0)); $args = array( ‘show_count’ => false, ‘hide_empty’ => true, ‘title_li’ => ”, ‘show_option_none’ => ”, ‘echo’ => false, ‘depth’ => 1 ); $args[‘child_of’] = $category[0]->term_id; // Get the category list $categories_list = wp_list_categories( $args ); if ( $categories_list … Read more

Get the page IDs of a Particular Menu item’s submenu

You can try the following function: function wpse_290320_get_page_ids_from_menu( $menu_id, $submenu_id ) { $menus = wp_get_nav_menu_items( $menu_id ); $pages = array(); foreach( $menus as $menu ) { if( $submenu_id == $menu->menu_item_parent && ‘page’ == $menu->object ) { $pages[] = $menu->object_id; } } return $pages; } $menu_id = 26; $submenu_id = 3298; $pages = wpse_290320_get_page_ids_from_menu( $menu_id, $submenu_id … Read more

After moving my site, sub-menus are not showing [closed]

For some reason, your header is being wrapped in the div with the class “page-wrap”, which should go around the whole page (that’s what is does on the working WooCommerce page). If you go into your inspector and uncheck “overflow:hidden” on the div with the class ‘page-wrap’, the menu starts working. Maybe check your header … Read more

Add (grand)child pages automatically to nav menu

It’s wise to avoid nav menus in cases like this where things may change frequently. Instead, you could look into using wp_list_pages() – with a custom walker if you need one to format it visually. Try wp_list_pages() right out of the box first and see whether you can just use CSS to style the list … Read more

Adding toggle-able element after menu item

You can easily add any HTML element to all menu items that have children by extending the Walker_Nav_Menu core class. The code below will add <i> icon element just after menu item </a> tag but you can of course change that if you need them inside or somewhere else by changing the $item_output variable. function … Read more

sub menu link is not working

This Code worked for me while ( odrin_have_rows(‘read_the_book_chapters’, $post_id) ) : the_row(); if (odrin_get_sub_field(‘sub’)){ $output .= ‘<li><ul>’; } $output .= ‘<li><a href=”#item’. $item_num = 1 . ‘”>’ . odrin_get_sub_field(‘title’, $post_id) .'</a></li>’;if (odrin_get_sub_field(‘sub’)){ $output .= ‘</ul></li>’;}$item_num++; endwhile; I was missing <li> of sub menu. Meaning that <ul> of sub menu should be within <li> of parent. … Read more

Use a filter on menu items that have children

There is indeed a filter, walker_nav_menu_start_el will be able to handle it for you! Take this code for example: function wpse356896_filter_primary_nav_menu_dropdown( $item_output, $item, $depth, $args ) { // Only for our primary menu location. if ( empty( $args->theme_location ) || ‘primary-menu’ !== $args->theme_location ) { return $item_output; } // Add the dropdown for items that … Read more