Primary and secondary menus

I am guessing you are gonna use pages or categories in the primary menu. The following code would need to be altered to work for custom taxonomies ( should work fine with custom post types also ). Put the following code in your themes functions.php: function km_dynamic_secondary_menu_reg() { global $km_nav_menus; $theme_location = ‘primary’; // replace … Read more

How to add a child item to a menu element (using wp_nav_menu_objects)

The WordPress functions changed since the answers here in 2014. As of today (Version 4.6.1) this code will create a main menu named “My Menu” , main item and sub item. To run code just paste and saves in your functions.php file in your child theme. $menu_id = wp_create_nav_menu(‘My Menu’); $parent_item = wp_update_nav_menu_item($menu_id, 0, array( … Read more