• 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!

Viewing 3 replies - 1 through 3 (of 3 total)
  • To clarify, under what conditions do you want the special menu to appear? Do you want the menu to appear if a single post is being displayed that has the specified tag?

    Thread Starter befranga

    (@befranga)

    Thanks for your reply!

    I have categories but also use tags to display posts. So I use archive for example

    <?php if (is_tag('mycustomtag')) : ?>

    I have a menu in my sidebar which should be displayed normally only change if archive or single or category has a specific tag. Then there should be a different menu (or sidebar if that is possible)

    I’m sorry, but I’m still a bit unclear. Why isn’t <?php if ( is_tag ( 'mycustomtag' ) ) : ?> sufficient for what you’re trying to accomplish?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘show menu if tag’ is closed to new replies.