WordPress menu in a shortcode

You can use the following code to put a menu in a shortcode:

function print_menu_shortcode($atts, $content = null) {
     extract(shortcode_atts(array( 'name' => null, ), $atts));
     return wp_nav_menu( array( 'menu' => $name, 'echo' => false ) );
}
add_shortcode('menu', 'print_menu_shortcode');Code language: PHP (php)

Source: