I think your scope is not the same. You are defining the $menu_name
in one scope and calling it in another scope. So you can do it with global
variable like below-
$GLOBALS[ 'menu_name' ] = 'Section 1 Menu';
And call it like-
<div id="nav">
<div class="close-menu"></div>
<?php
wp_nav_menu(
array(
'menu' => $GLOBALS[ 'menu_name' ],
'theme_location' => 'primary',
'depth' => 1,
'menu_class' => 'main-menu',
'menu_id' => 'main-menu'
)
); ?>
<div class="header-tools">
<div class="icon-list">
<a href="https://wordpress.stackexchange.com/help" class="icon help trigger-help" title="help"></a>
<a href="http://wordpress.stackexchange.com/dashboard" class="icon account" title="my account"></a>
</div>
</div>
</div>
Hope that helps.
Related Posts:
- Mega Menu Walker
- start_lvl Ignored in Custom walker_nav_menu
- Displaying Logged-In User Name in WordPress Menu
- Hide main div if wp_nav_menu is empty
- How to store the_title() into a variable to reutrn the value, not just echo it
- How do I make my function add variables/values to the $post object?
- Check if a menu is empty?
- How to remove a metabox from menu editor page?
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- How to add active class to custom menu using while loop and wp_list_pages
- Cleanest/Fastest way to avoid calling and retrieving data from the database multiple times?
- How do I know what variables are passed in a filter/action and what their meaning is?
- WordPress menu deletes when trying to add a hook
- Logout and redirect using the WP Menu
- Have CSS Class Added with `is_page()` WP function
- Count the number of times the search form template gets included on a page
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Run a filter when a walker runs
- Menu — How to add “current-menu-grand-ancestor” css class
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- How to put a variable in a instance in the widget
- How can I Add a variable PHP in the Menu Nav
- Get value from shortcode to do something
- Automatically adding new post categories to menu
- Add data attribute to each li in menu
- Unique icons next to each WordPress menu item
- Child page menu in sidebar
- Title Case WordPress Menu Items
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- How to change menu order item
- Add item to top of menu using a filter in functions.php
- Register a menu – Error Header
- Creating WordPress Shortcode with Variable
- Add login hyperlink to secondary navigation menu
- Add value to new attribute inside WordPress menu items
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Get the name of menu item with wp_nav_menu
- How to reference PHP in Javascript
- Overide Variable in Child Theme
- How to add aria role and schema markup to custom walker container
- How can I use custom menus with a Bootstrap WordPress theme?
- Nav-Menu not showing up
- Remove submenu item from list
- Dynamic Menu drops pages?
- Menu not styling. New menus functionality giving me a headache
- how to changes mobile menu toggle breakpoint in WordPress
- How to display already created menus via php?
- How to send a php var to jQuery Ajax call with two different file
- Providin exception to WordPress wp_nav_menu Custom CSS Classes
- Custom global variable not working in function
- Best way to use variables in multiple functions?
- Trying to add some custom text into WordPress Post title via function.php
- How to put 2 php codes in functions.php without site crashing
- Menu not updating for logged in users after redirect
- How do I fix Undefined variable using $_POST in function?
- Add element after navigation element title don’t works like I expect
- Add parent menu item in sub-menu in custom nav_walker
- Fatal error when using array_diff() function inside of wp_update_nav_menu hook?
- Where can I find the declaration of `$_wp_theme_features`?
- How I can add div to menu?
- WordPress adding in site URL to header links
- Custom Navigation Bar JSON Syntax Error in JSON at Position 0
- How to add different menu items on different menus?
- How to access admin menu labels and links on front-end?
- How to get default variation ID (woocommerce)
- Get check box values inside array for use in posting form data
- Create another “Display Site Title and Tagline” checkbox, “Header Text Color” setting and control
- Trying to establish connection to External Database
- Call global variable array() in woocommerce child/template
- add_action shortcut?
- Passing the custom field values in the wp_get_current_user array function
- Using fwrite() and “a” appends multiple times instead of once
- How to output a PHP file values by shortcode?
- Showing content from one page on another
- How to style options page in dashboard?
- How to insert a single row to WP database table?
- Get date numerical and separate?
- Where in PHP do I move title and meta (date) to bottom of each blog section?
- Change list item content in menu navigation to add a child element with specific class
- get_term_link() returns correct – But illogical error-messages disturb
- WSoD being caused by this piece of code
- Converting HTML Template to WordPress Theme
- Set the background to a default image if there isn’t a specified “featured image”
- How to Arrange PHP Files to Allow for Multiple Types of Pages?
- Add a variable in functions.php and call it in single.php
- How to access global variable $menu inside a class function
- Calling directories to load in wordpress
- WordPress add post format support not working
- Can I prevent the user from adding more than two levels deep of terms inside of a taxonomy metabox?
- Image media upload metabox
- Menu Limitations
- How to remove the cufon script from Dzonia Lite theme [closed]
- How to remove or change the “W” icon in “My Sites”?
- get a simple array of all of the term names that exist in all taxonomies
- Login/logout in header
- How to display posts by current user in a drop down
- Logged in user ID as post ID
- How does WordPress insert Paragraphs in posts