in functions.php, I've defined the following:
register_nav_menu( 'home_blocks', __( 'Home Page Posts', 'my_Theme' ) );
In /wp-admin/nav-menus.php
, I've added a menu called Home Page Posts and assigned 3 posts to it and set it to be the item associated with Home Page Posts as the menu location.
In index.php
, I've added the following:
if ( has_nav_menu( 'primary' ) ) {
echo 'has primary<br />';
} else {
echo 'no primary<br />';
}
if ( has_nav_menu( 'home_blocks' ) ) {
echo 'has home blocks<br />';
} else {
echo 'no home_blocks<br />';
}
Both of the successful conditions are echoed.
When I try to return the menu contents so I can run some inline custom output based on post_id, I attempted the following code and got NULL or string(0) "", depending on what values I put for the location and menu name. What way are these values associated and how would I get the menu back?
$defaults = array(
'theme_location' => 'home_blocks',
'menu' => '',
'container' => '',
'container_class' => '',
'container_id' => '',
'menu_class' => '',
'menu_id' => '',
'echo' => 1,
'fallback_cb' => '',
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
'items_wrap' => '',
'depth' => 0,
'walker' => ''
);
$menu = wp_nav_menu( $defaults );
var_dump( $menu );