How do I make a page (dis)appear conditionally in a menu? I had something like this in mind:


I would prefer an answer that doesn't incorporate an external plugin.

  • do you mean a wp_nav_menu? – Milo Oct 10 '13 at 20:21

You can use wp_nav_menu_objects or wp_nav_menu_items hooks to add your filter function.

function my_hide_menu_items($objects) {
    if ( is_admin() ) return $objects;

    foreach ( $objects as $k=>$object ) {
        if ( YOUR CONDITION ) {  // if $object shouldn't be displayed
    return $objects;
add_filter('wp_nav_menu_objects', 'my_hide_menu_items', 10, 2);
  • Exactly what I was looking for, many internets for you, sir! – Joren Oct 10 '13 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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