WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
do you mean a wp_nav_menu? – Milo Oct 10 '13 at 20:21
up vote 1 down vote accepted

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);
share|improve this answer
Exactly what I was looking for, many internets for you, sir! – Joren Oct 10 '13 at 21:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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