Skip to content

Instantly share code, notes, and snippets.

@iamchetanp
Last active August 26, 2018 11:28
Show Gist options
  • Save iamchetanp/13cd6acfe57c878d8734f13b130a19ac to your computer and use it in GitHub Desktop.
Save iamchetanp/13cd6acfe57c878d8734f13b130a19ac to your computer and use it in GitHub Desktop.
Create shortcode to get WordPress menu in HTML format.
/**
* Create shortcode to get WordPress menu in HTML format.
* How to use? [cp_wp_menu name="Main Menu"]
*
* @param array $atts Array of attributes.
*
* @return string HTML menu.
*/
function cp_wp_menu_shortcode( $atts ) {
$menu = shortcode_atts( array(
'name' => null,
), $atts );
return wp_nav_menu( array(
'menu' => $menu['name'],
'echo' => false,
) );
}
add_shortcode( 'cp_wp_menu', 'cp_wp_menu_shortcode' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment