Title: context sensitive menu
Last modified: August 21, 2016

---

# context sensitive menu

 *  Resolved [meischder](https://wordpress.org/support/users/meischder/)
 * (@meischder)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/context-sensitive-menu/)
 * Hi,
 * I’d like to create a Menubar, for which I can choose between predefined items
   and a context sensitive list starting with the parent of the current page. Is
   there a place where I can insert custom code for choosing between the two types
   in the admin-menu and for creating the actual menu?
 * Thanks,
 * meischder
 * [https://wordpress.org/plugins/menubar/](https://wordpress.org/plugins/menubar/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * (@dontdream)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/context-sensitive-menu/#post-4713165)
 * Hi Meischder,
 * As you know you can display a menubar with the code
 * `<?php do_action('wp_menubar','your_menu_name_here'); ?>`
 * So you could write:
 *     ```
       <?php
       if ( your condition ) do_action('wp_menubar','your_menu_name_here');
       else { your custom code }
       ?>
       ```
   
 * You could also try the feature described in this page:
 * [http://dontdream.it/menubar/the-menubar-php-type/](http://dontdream.it/menubar/the-menubar-php-type/)
 *  Thread Starter [meischder](https://wordpress.org/support/users/meischder/)
 * (@meischder)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/context-sensitive-menu/#post-4713168)
 * Hi Andrea,
 * thanks for your reply.
    Nevertheless my problem is not the choice of the menu,
   but the use of the optical structure (css etc.) of the created menubar. The thing
   I want is having the option which menu-type (context-sensitive or predefined)
   when creating one. Depending on your choice you’ll get the normal wpm-admin menu
   or you don’t. When the user wants a context-sensitive menu I want to build this
   menu in the existing structure of the plugin. Thus I can change the layout in
   css for both menus without changing entries in two css-files. I’m thinking about
   a kind of method which returns either the context-menu or forwards the return
   of the existing methods.
 * Thanks,
 * meischder
 *  Plugin Author [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * (@dontdream)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/context-sensitive-menu/#post-4713207)
 * I’m not sure you can do what you need with the existing plugin version.
 * What you can do is:
 * 1. Build two different menus with the same CSS template, and switch between them
   with PHP code:
 *     ```
       <?php
       if ( choice ) do_action('wp_menubar','first_menu');
       else do_action('wp_menubar','second_menu');
       ?>
       ```
   
 * 2. Build a menu with dynamic items (PHP type items) and code those items to behave
   as you need. Examples are in [http://dontdream.it/menubar/the-menubar-php-type/](http://dontdream.it/menubar/the-menubar-php-type/)
 * More complex choices are not supported by the current plugin version.
 *  Thread Starter [meischder](https://wordpress.org/support/users/meischder/)
 * (@meischder)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/context-sensitive-menu/#post-4713218)
 * With the first one I only can choose between static predefined menus.
    The second
   one would be possible. But by using this method I first restrain the number of
   possible menu items because you can just define n items. Second it is less efficient
   since I have to put a request to the database for each item and choose the nth
   entry from this ordered list. Especially if there is actually only one item but
   10 predefined items the code runs 10 times.
 * So I’m actually looking for the place in the code where the menu is built when
   loading the page. There I could choose if I want to return a list of predefined
   menu items or a list of the current siblings.
 * Greetings,
    meischder
 *  Plugin Author [Andrea Tarantini](https://wordpress.org/support/users/dontdream/)
 * (@dontdream)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/context-sensitive-menu/#post-4713225)
 * I didn’t understand you are willing to edit the plugin code. Sorry!
 * The menu output happens in the template file, e.g. for the Superfish template
   it happens in the function _wpm\_display\_Superfish()_, file _menubar/templates/
   Superfish/wpm3.php_. That function in turn calls the function _wpm\_out41()_,
   file _menubar/wpm-menu.php_, that generates the actual menu.
 * Hope that helps!
 *  Thread Starter [meischder](https://wordpress.org/support/users/meischder/)
 * (@meischder)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/context-sensitive-menu/#post-4713252)
 * Yes that helps.
    Thank you for your effort.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘context sensitive menu’ is closed to new replies.

 * ![](https://ps.w.org/menubar/assets/icon-128x128.png?rev=1569441)
 * [Menubar](https://wordpress.org/plugins/menubar/)
 * [Support Threads](https://wordpress.org/support/plugin/menubar/)
 * [Active Topics](https://wordpress.org/support/plugin/menubar/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/menubar/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/menubar/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [meischder](https://wordpress.org/support/users/meischder/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/context-sensitive-menu/#post-4713252)
 * Status: resolved