0

I have a menu that I only want to show on certain pages using the following code:

<?php if ( is_front_page() || is_archive() || is_404() ) {

}
else
{

if ( function_exists('has_parent') ) {

    $id = get_the_ID();
    $menu_to_use = get_post_meta($id, 'themestore-meta-menu-name', 1);
    echo '<nav class="nav-container group" id="nav-subheader">';
    echo '<div class="nav-toggle" id="nav-subheader-toggle"><i class="icon-reorder"></i></div>';
    wp_nav_menu( array('menu' => $menu_to_use, 'menu_class' => 'nav container group', 'container' => '' )); 
     echo '</nav>';
}
}

?>

I have a custom taxonomy and post type that I DON'T want the menu to show up on for single post pages. I've tried the following and none seem to work:

if ( is_front_page() || is_archive() || is_404() || is_singular('tips') )
if ( is_front_page() || is_archive() || is_404() || is_tax('tips') )
if ( is_front_page() || is_archive() || is_404() || taxonomy_exists('tips') )
if ( is_front_page() || is_archive() || is_404() || 'tips' == get_post_type() )
if ( is_front_page() || is_archive() || is_404() || is_category('tips') )

And I've tried both custom functions from this answer: If is custom post type

It would seem that one of those should work but none of them hide the menu. What am I missing?

closed as too localized by fuxia Jun 17 '13 at 20:24

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • I'm such an a**. I was using the wrong name for the post type. I'm sorry to have bothered anyone. – Justice Is Cheap Jun 17 '13 at 19:18
1

For custom post types use is_post_type_archive('tips'). Let us know if this works. It should also work with an array is_post_type_archive( array( 'tips', 'cpt', 'another cpt' ) )

I am currently using this function to recognize specific post type archives.

See: A Post Type Archive in codex.

It would be best if you could specify which cases the menu should be generated instead of which cases it shouldn't. Although, you should be able to use !is_post_type_archive('tips') as well. On which pages do you specifically want these actions to be performed?

if (    ( is_page() 
        && $post->post_parent 
        && !is_front_page() 
        && !is_archive() 
        && !is_404() 
        && !is_post_type_archive('tips') ) {
    $id = get_the_ID();
    $menu_to_use = get_post_meta($id, 'themestore-meta-menu-name', 1);
    echo '<nav class="nav-container group" id="nav-subheader">';
    echo '<div class="nav-toggle" id="nav-subheader-toggle"><i class="icon-reorder"></i></div>';
    wp_nav_menu( array('menu' => $menu_to_use, 'menu_class' => 'nav container group', 'container' => '' )); 
    echo '</nav>';
}
  • Hey Ryan, thanks for the suggestion but that didn't work for me. The only thing that seems to work is is_single(). – Justice Is Cheap Jun 17 '13 at 18:23
  • I'm not sure this part of the code is good practice or that it will ensure that the conditions will be met before proceeding. if ( is_front_page() || is_archive() || is_404() ) { } – iyrin Jun 17 '13 at 19:00
  • We're creating pages and sub-pages that each have their own custom menus that the editor can choose at the time of creation. So, the menu is getting created after the section is created and the menu chosen dynamically. That's why I went with the option of excluding instead of including. Also, I tried the code you provided and the menu showed up on the homepage, the archive and the 404 and still showed on the tips posts page. – Justice Is Cheap Jun 17 '13 at 19:01
  • Ok. My comment has been edited. Does that code help you exclude 'tips' before loading the menu? The ! is just saying it "is not" instead of "is". – iyrin Jun 17 '13 at 19:03
  • Just in case you didn't notice, I replied in the comment above. – Justice Is Cheap Jun 17 '13 at 19:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.