show menu if tag
-
I hope this is possible. I want to show a certain menu only when there is a certain tag. Is that even possible?
This is what I figured out so far: `<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
if ($tag->name == “mycustomtag” ) {wp_nav_menu( array( ‘theme_location’ => ‘secondary’, ‘container’ => ‘dropdown clearfix’, ‘menu_class’ => ‘nav nav-stacked’, ‘menu_id’ => ‘side’));
} else {
wp_nav_menu( array( ‘theme_location’ => ‘primary’, ‘container’ => ‘dropdown clearfix’, ‘menu_class’ => ‘nav nav-stacked’, ‘menu_id’ => ‘side’));
}
}}
?>`As it is a menu, it’s outside the loop.
If I simply put
<?php if (is_tag('mycustomtag')) : ?>
it shows correctly on archive pages but not on other pages.
Thanks!
- The topic ‘show menu if tag’ is closed to new replies.