The value of $menu_id is not initialized if the menu already exists. So, if on theme activation, $menu_exists is true, $menu_id will never be set to a value and this line should produce a PHP warning:
$locations[$menulocation] = $menu_id;
You could try adding it like this:
if ( $menu_exists ) {
$menu_id = $menu_exists->term_id;
} else {
// Menu doesn't exist, let's create it.
$menu_id = wp_create_nav_menu( $menu_name );
wp_update_nav_menu_item( $menu_id, $new_page_id, array(
'menu-item-title' => __( $new_page_title ),
'menu-item-url' => home_url( $new_page_slug ),
'menu-item-status' => 'publish' ) );
}
That may not fix your problem. I couldn’t test some things without knowing more about the theme settings.
Related Posts:
- Menu items description? Custom Walker for wp_nav_menu()
- How can I display a menu on certain pages only?
- Add Caret to Menu Items with Sub-Menus in WordPress Theme
- How to limit wordpress menu depth in admin panel
- wp_nav_menu sort order?
- How to determine if custom menu is active?
- Any walker causes blank menu?
- How to add menu support to a theme?
- Extend walker – navigation, adding data attribute to a tag
- Get last modified date for menu link
- Replace Home with image link inside custom header menu
- How to add nofollow to wp_nav_menu
- How to highlight the current page in the nav menu?
- How do I add a post to a menu
- how to change WordPress menu markup/classes
- Setting a Default ‘Theme Location’ When Creating a Menu
- Best practices: Custom theme sidebar menu – hardcode or widget?
- How do I highlight the menu for a child page?
- Custom Nav Walker Displaying Values in Sub Menu
- how to set more than one menus to the same theme location
- Custom Nav Walker to show siblings and children of current branch?
- CSS won’t style output of wp_nav_menu() correctly
- Create self-populating menu and add extra divs to the menu layout
- Where is definied the theme location for the main menu in a WordPress template?
- how to wrap tag in tag html to wordpress menu conversion
- Second menu not showing
- menu behavior is not as expected
- Set default screen option for appearance -> menus
- Part of Menu Item Hidden on Header Menu
- wp_nav_menu add something before closing container and after last list item
- Find the Children of a Page then Echo it as a Bulleted List of Links (menu)
- which is the best way to customize nav-menu-template.php?
- Create wordpress header with custom logo in between the menu splitting the menu into two equal parts [closed]
- My Admin bar covers my sticky navbar [closed]
- Menu item added in wp_nav_menu_items filter is never highlighted
- WordPress empty Nav Menu error
- Single-level menu option? Another way?
- Primary navigation menu & footer not showing in category / tag page
- Using a page as home, how do I prevent nav from setting both home and page links active?
- Problem with empty class attributes when running a filter on nav_menu_css_class
- How to append to menu items selectively
- Custom Nav Walker Trouble
- How to set the currently active page in the menu including parents
- Issue on Adding A Class to Bootstrap Navbar Walker Dropdown
- Show woocommerce categories on my theme menu styling
- Where am I doing wrong in my theme menu?
- Custom Navigation build using wp_nav_menu and walker
- Override customizer values on a per-menu base
- Recommended method for updating/adding menus when adding new theme
- Child Theme header1.php file not overwriting parent theme’s header1.php file
- Why wp_nav_menu() doesnt show the proper meny when invoked two consecutive times?
- How to develop a menu like wwe.com?
- 3 Level Deep Navigation Menu Not Showing All Levels
- Why are some of my menu items not displaying on my menu?
- How to Create custom xml file for demo content for custom theme?
- How to add menù section to my WordPress template?
- How can i make multilevel menu in wordpress theme with bootstrap
- how do i develop a global nav and local nav to be wordpress dynamic?
- Navbar- disable “onClick” drop-down
- Adding content inside the anchor tags within WordPress main nav
- Why is my container argument not working for wp_nav_menu() [closed]
- How to Emulate Default Navigation Menu Behaviour in a Custom Theme?
- Some doubts about WordPress handle the horizontal main menu visualization
- Does wordpress add their own classes into nav menus?
- Custom menu: Link names
- Parent/Child pages
- How to substitute old wordpress menu by wp 3 menu the right way?
- if (has_custom_menu())?
- Why do sticky posts show in this menu?
- Making a horizontal flyout menu from WordPress category listing
- Archives and Categories in Custom Menu
- Wrong activation/confirmation link in email
- how to create/register menu items that can be added to menus later
- Why nav_menu_css_class doesn’t work with apply_filters?
- 3 Level Menu Navigation (3rd Level not displaying)
- Use instead of for wp_nav_menu()
- Theme: dropdown hover menu not showing up in IE/Edge
- Pages not displaying as sections on static page
- Cold Fusion to WordPress
- Menu names not getting translated
- Nav menus Fast previewing not working with wp_get_nav_menu_items!
- Need help with adding custom wordpress menu and sub-menu
- HTML TO WP Theme : Submenu goes down wp_nav_menu
- wp_nav_menu custom walker class
- Fallback dosen’t work when not using ‘menu’ attribute
- How to add custom nav_menu_css_class to certain menu only?
- WordPress doesn’t recognize submenus as so I can’t style them properly
- Primary Menu Showing All Pages With No Sub-Nav
- How to add drop symbol to parent nav items which have child
- How to add custom field option with menu?
- WordPress 3.9 two menus in same position?
- Main Menu Theme Different Output Print
- How do I move menu to the bottom in Custom Community theme?
- Creating Multiple Menus in the Thesis Theme?
- How to make navigation a list without a plugin? [duplicate]
- How do I middle-align my header menu items in WordPress [closed]
- How to automatically set a Template Page Name next to a page in menu screen such as WooCommerce pages, front page, or posts page in wordpress?
- Dynamic nav menu with icons [closed]
- wp_nav_menu_items callback not triggered
- Why is wp_nav_menu() not removing the container around the nav ?