I'm currently retrieving a nav menu based on the parent page's title, and if the page doesn't have a parent then it's own title.
global $post;
$page_title;
if ($post->post_parent) {
$page_title = get_the_title($post->post_parent);
} else {
$page_title = get_the_title($post);
}
$sidebar_title = 'Sidebar - '.$page_title;
wp_nav_menu(array( 'menu' => $sidebar_title));
Instead of first checking for a parent, I'd like to first check if a page has it's own unique menu. This is what I wrote but it doesn't work:
global $post;
$page_title = get_the_title($post);
$sidebar_title = 'Sidebar - '.$page_title;
if ( !wp_nav_menu(array( 'menu' => $sidebar_title, 'echo' => false )) ) {
$page_title = get_the_title($post->post_parent);
$sidebar_title = 'Sidebar - '.$page_title;
}
wp_nav_menu(array( 'menu' => $sidebar_title ));
TLDR: How do I check if a menu exists?
dynamic_sidebar()
), or 3) a template-part file (get_sidebar()
/sidebar.php
).