0

I looked around and couldn't get any answer that helped me.

I have an include that I am calling in multiple headers (I have different headers for different sections of a membership site that need different menus and resources.)

template-main-nav.php:

<div id="nav">
    <div class="close-menu"></div>
<?php
wp_nav_menu(
    array(
        'menu'              => $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="/help" class="icon help trigger-help" title="help"></a>
            <a href="/dashboard" class="icon account" title="my account"></a>
        </div>
    </div>
</div>

and above the header in each header-x.php file I am declaring the $menu_name variable:

<?php
    $menu_name = 'Section 1 Menu';
    get_template_part('template-main-nav');
?>

I want multiple different menus I've created in the admin to go into the same location and this seemed like the best solution. The thing is I can't get the variable to pass, no matter how I format it. What am I doing wrong?

1 Answer 1

0

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="/help" class="icon help trigger-help" title="help"></a>
            <a href="/dashboard" class="icon account" title="my account"></a>
        </div>
    </div>
</div>

Hope that helps.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.