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?
- Allowed memory size of 268435456 bytes exhausted (tried to allocate 7146491840906359738 bytes)
- How do I get the author’s page url from their ID?
- Wrap each shortcode in array to div
- Check if Product is in a Specific Category in Functions.php
- Adding ads code between comments
- How to Display Image Meta underneath EVERY image in EVERY post
- Limiting woocommerce line_total decimal length
- Shortcode content filter?
- Input type search in Menu
- only show container with next/prev links if they exist?
- JS file work only in index page
- Custom shortcode outputs plain text instead of HTML at top of post
- how can i use $_COOKIE[] + PostID to execute the below code?
- Default menu editor with automatic page list
- height should be set to auto to avoid pixelation in the post thumbnail function
- Can i put my shortcode inside a variable in php files?
- Can’t access site after making changes to the functions.php [closed]
- Simple AJAX notification when the new post is added to the database
- Upload multiple files in randomly generated folder using wp_upload_bits
- Personalize checkout text
- Adding an interior ‘hero’ area with some added php title customization
- Call to undefined function error in plugin
- Creating customized php files in theme folder
- Disclaimer that will show every refresh of the page
- Dynamically switch file in get_template_directory_uri() | Function [closed]
- Woocommerce My acount page
- Child theme overirde template-tags in a theme built on underscores in inc/template-tags
- Two theme locations for two menus, but only one is showing up
- Display Year and Month from custom field + Age Calculator
- Contact form field in wordpress menu
- Get author meta of all writers
- Nav Menu Display
- WP Fatal error: Call to undefined function get_template_directory_uri()
- Remove default Image Sizes
- how to create twitter card without plugin in wordpress website?