I have this bit of code in my header:
<?php if (has_nav_menu('sub-header-menu', 'responsive')) { ?>
<?php wp_nav_menu(array(
'container' => '',
'menu_class' => 'sub-header-menu',
'theme_location' => 'sub-header-menu')
);
?>
<?php } ?>
And I need something that will make it only show on the blog page and the children for that page (i.e the categories).. I'm not great with PHP but I guess this would be something simple
Just add a page Id of your blog page in you condition.
$parentPageId = is_subpage();
if (has_nav_menu('sub-header-menu', 'responsive') &&
(is_page( $blogPageId ) || $parentPageId == $blogPageId))
You can alos check your page using slug.
is_page( 'blog' )
Function to get Parent Page Id if exists.
function is_subpage() {
global $post;
if ( is_page() && $post->post_parent ) {
return $post->post_parent;
} else {
return false;
}
}
Find out the ID of the blog page $blogid = 123
(for example) and then check with if ($page->ID == $blogid) { /*show menu*/ }