How can I add a sub menu to an existing navigation menu in WordPress?

I got the answer, here it is: I want to add submenus ffrom database to the menu named ‘Products’ Create a custom plugin and install it through Admin panel. Inside the functions.php write this code. This is upgrade safe way and will not brake if the theme is updated. add_filter( ‘wp_nav_menu_objects’, ‘ravs_add_menu_parent_class’ ); function ravs_add_menu_parent_class( … Read more

Generate a Menu that displays all child pages of top level parent

Here is a function that will output the top level parent along with all of the children of the current page. Helpful menu classes are added to the output. E.g. page_item_has_children, current_page_item, current_page_ancestor, etc. This solution is based on one of the examples in the documentation for wp_list_pages() and this answer here on WPSE, which … Read more

Add items to a menu dynamically

You could achieve this with a custom walker function, on your menu. a very simple example: class Walker_WPA82563_Submenu extends Walker_Nav_Menu { function end_el(&$output, $item, $depth=0, $args=array()) { if( ‘Boats’ == $item->title ){ $output .= ‘<ul><li>Dynamic Subnav</li></ul>’; } $output .= “</li>\n”; } } Then where you call the nav menu, create an instance of your custom … Read more

Category menu item and its last 10 posts as sub-menu

I finally achieve it with this code in function.php // Front end only, don’t hack on the settings page if ( ! is_admin() ) { // Hook in early to modify the menu // This is before the CSS “selected” classes are calculated add_filter( ‘wp_get_nav_menu_items’, ‘display_lasts_ten_posts_for_categories_menu_item’, 10, 3 ); } // Add the ten last … Read more

Moving Categories submenu to Media, but still opens Posts menu

To add to what @brasofilo answered 3 years ago, this is what is necessary in the current menu system (WP v4.5.1). add_action( ‘admin_head-edit-tags.php’, ‘modify_menu_highlight_wpse_43839’ ); function modify_menu_highlight_wpse_43839() { if( ‘post_tag’ == $_GET[‘taxonomy’] ) { ?> <script type=”text/javascript”> jQuery(document).ready( function($) { $(“#menu-posts, #menu-posts a”) .removeClass(‘wp-has-current-submenu’) .removeClass(‘wp-menu-open’) .addClass(‘wp-not-current-submenu’); $(“#menu-media, #menu-media > a”) .addClass(‘wp-has-current-submenu’); }); </script> <?php } … Read more