Variables within wp_nav_menu

I have a left and right wp_nav_menu which displays on the front-end as one unordered list:

<nav>
<ul>
<?php
// Left menu
wp_nav_menu( array(
‘theme_location’ => ‘left’,
‘container’ => false,
‘menu_class’ => false,
‘items_wrap’ => ‘%3$s’ // Removes <ul> and wraps <li>
) );
// Right menu
wp_nav_menu( array(
‘theme_location’ => ‘right’,
‘container’ => false,
‘menu_class’ => false,
‘items_wrap’ => ‘%3$s’ // Removes <ul> and wraps <li>
) );
?>
</ul>
</nav>

As I’m repeating code here, I’ve created a variable called $menu, like so:

<nav>
<ul>
<?php
// Left
$menu = array(‘container’ => false, ‘menu_class’ => false, ‘items_wrap’ => ‘%3$s’);
wp_nav_menu( array(
‘theme_location’ => ‘left’,
$menu
) );
// Right
wp_nav_menu( array(
‘theme_location’ => ‘right’,
$menu
) );
?>
</ul>
</nav>

Is this the correct way of calling a variable within an array or is there a more efficient way of doing it?

Read more here:: Variables within wp_nav_menu

Leave a Reply

Your email address will not be published. Required fields are marked *