Title: Show wp_nav_menu(); in shortcode?
Last modified: February 26, 2017

---

# Show wp_nav_menu(); in shortcode?

 *  Resolved [Matt Blank](https://wordpress.org/support/users/mattblank/)
 * (@mattblank)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/show-wp_nav_menu-in-shortcode/)
 * Hi,
 * I used this within my theme to generate the sites menu:
 * `<? wp_nav_menu(); ?>`
 * I want to have this now here in the shortcode, something like this:
 * `<?php echo do_shortcode('[expand title="Menu"]<? wp_nav_menu(); ?>[/expand]');?
   >`
 * That breaks the PHP though. Can anybody help me to tell me how this is done?
 * Thanks!
    Matt
    -  This topic was modified 9 years, 3 months ago by [Matt Blank](https://wordpress.org/support/users/mattblank/).

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

 *  Plugin Author [twinpictures](https://wordpress.org/support/users/twinpictures/)
 * (@twinpictures)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/show-wp_nav_menu-in-shortcode/#post-8852467)
 * Hello.
 * Try:
 *     ```
       <?php echo do_shortcode('[expand title="Menu"]'.wp_nav_menu().'[/expand]'); ?>
       ```
   
 * It sounds like you are trying to add the collapse function to your navigation
   menus. Normally this is a default feature of your theme. However, if you want
   to include the collapse-o-matic expand elements as part of your wp_nav_menu, 
   you will want to look into creating a [nav walker](https://codex.wordpress.org/Class_Reference/Walker).
   This is quite advanced, and beyond the scope of our plugin. But we’ll help point
   you where you need to go.
 * One other tip, check out the [roll-your-own method](http://spacedonkey.de/1247/collapse-o-matic-the-roll-your-own-method/),
   as using the do_shortcode function instead of the nav_walker class will probably
   not perform as expected.
 * Best of luck!
    -  This reply was modified 9 years, 3 months ago by [twinpictures](https://wordpress.org/support/users/twinpictures/).
 *  Thread Starter [Matt Blank](https://wordpress.org/support/users/mattblank/)
 * (@mattblank)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/show-wp_nav_menu-in-shortcode/#post-8854047)
 * That works, but for some reason it’s always expanded, never collapsed. I’m using
   this for mobile only, which is the need to use this. So the whole thing is within
   a hidden div, which only shows when the viewport is of a certain size.
 * I have it working fine if I actually put text in there. But the moment I put 
   PHP code in, it breaks.
 * Matt
 *  Plugin Author [twinpictures](https://wordpress.org/support/users/twinpictures/)
 * (@twinpictures)
 * [9 years, 3 months ago](https://wordpress.org/support/topic/show-wp_nav_menu-in-shortcode/#post-8873270)
 * What you are doing is a bit advanced. you might consider upgrading to [collapse-pro-matic](https://plugins.twinpictures.de/premium-plugins/collapse-pro-matic/)
   for the very high level of personal support it comes with: We would even resolve
   this issue for you.
 * If you want to forge forward on your own, you will have to be more detailed. 
   Post an example of both the code that works compared to what does not work.
 * Also, post a link to what works but is always expanded.
 * We’ll do what we can to help, but if you go pro, [you won’t be disappointed](https://plugins.twinpictures.de/testimonial/collapse-pro-matic/).

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

The topic ‘Show wp_nav_menu(); in shortcode?’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/jquery-collapse-o-matic_fffeff.svg)
 * [Collapse-O-Matic](https://wordpress.org/plugins/jquery-collapse-o-matic/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/jquery-collapse-o-matic/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/jquery-collapse-o-matic/)
 * [Active Topics](https://wordpress.org/support/plugin/jquery-collapse-o-matic/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/jquery-collapse-o-matic/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/jquery-collapse-o-matic/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [twinpictures](https://wordpress.org/support/users/twinpictures/)
 * Last activity: [9 years, 3 months ago](https://wordpress.org/support/topic/show-wp_nav_menu-in-shortcode/#post-8873270)
 * Status: resolved