WordPress.org

Ready to get started?Download WordPress

Plugin Directory

If Menu

Show/hide menu items with conditional statements

How can I add a conditinal statement for menu items?

New conditional statements can be added by any other plugins or themes.

Example of adding a new conditional statement for disaplying/hiding a menu item when current page is a custom-post-type.

// theme's functions.php or plugin file
add_filter( 'if_menu_conditions', 'my_new_menu_conditions' );

function my_new_menu_conditions( $conditions ) {
  $conditions[] = array(
    'name'    =>  'If single custom-post-type', // name of the condition
    'condition' =>  function($item) {          // callback - must return TRUE or FALSE
      return is_singular( 'my-custom-post-type' );
    }
  );

  return $conditions;
}

Where do I find conditional functions?

WordPress provides a lot of functions which can be used to create conditional statements for almost any combination that a theme/plugin developer can think of.

Requires: 3.7 or higher
Compatible up to: 3.9.1
Last Updated: 2014-6-22
Downloads: 11,628

Ratings

4 stars
4.9 out of 5 stars

Support

1 of 2 support threads in the last two months have been resolved.

Got something to say? Need help?

Compatibility

+
=
Not enough data

1 person says it works.
0 people say it's broken.

0,1,0
100,1,1
100,1,1
100,1,1
0,1,0
100,1,1