Add value to Wordpress Array

So I’m using the plugin Advanced Custom Fields which is a Wordpress plugin. I’m able to echo the value for $Menu outside of the array just fine when I try it. However, I’d like to make the value for menu in the array to be ‘menu’ => $Menu. I tried echoing it and now I’m trying to push it onto the array. What am I doing wrong here?

<?php $Menu = get_field('services_list_for_this_page'); ?>
                                                       
<?php wp_nav_menu($SideNav = array(
        'depth' => 2,
        'menu_class' => 'ServicesLeftNav',
    )
); ?> 
                                                                     
<?php array_push($SideNav, "menu => $Menu"); ?>

Hi Brian,

Just assign $Menu as an element of the new array as you’re creating it:

wp_nav_menu($SideNav = array(
        'depth' => 2,
        'menu_class' => 'ServicesLeftNav',
        'menu' => $Menu
    )
);
1 Like

That worked. thx. I tried that before, but I must have had something wrong.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.