{"id":8252,"date":"2021-02-15T11:36:34","date_gmt":"2021-02-15T11:36:34","guid":{"rendered":"https:\/\/www.wpexpertdeveloper.com\/?p=8252"},"modified":"2021-02-24T04:41:03","modified_gmt":"2021-02-24T04:41:03","slug":"building-wordpress-shortcode-navigation-menu","status":"publish","type":"post","link":"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/","title":{"rendered":"Building a WordPress Navigation Menu Shortcode for Posts and Pages"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"8252\" class=\"elementor elementor-8252\">\n\t\t\t\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-646242d0 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"646242d0\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-69bc3d98\" data-id=\"69bc3d98\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t\t\t<div class=\"elementor-element elementor-element-41c7b28b elementor-widget elementor-widget-text-editor\" data-id=\"41c7b28b\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<!-- wp:paragraph -->\n<p>Navigation menu is a built-in WordPress feature, implemented by the theme. We have the ability to add any number of navigation menus from the backend section of WordPress. However, default theme features don&#8217;t support displaying menus inside posts or pages. In this tutorial, we are going to build a shortcode for displaying a navigation menu inside a post or page. A shortcode based navigation menu is useful for adding a post or page specific menu instead of the common navigation in the header or footer of the site.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph --><!-- \/wp:paragraph -->\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-19e802c elementor-widget elementor-widget-video\" data-id=\"19e802c\" data-element_type=\"widget\" data-settings=\"{&quot;youtube_url&quot;:&quot;https:\\\/\\\/youtu.be\\\/QuGyHf2ZMYg&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}\" data-widget_type=\"video.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-wrapper elementor-open-inline\">\n\t\t\t<div class=\"elementor-video\"><\/div>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-6c440ce elementor-widget elementor-widget-text-editor\" data-id=\"6c440ce\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<!-- wp:paragraph --><!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p>Let&#8217;s get started.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph {\"customTextColor\":\"#ffffff\",\"customBackgroundColor\":\"#5cb7ec\"} -->\n<p class=\"has-text-color has-background\" style=\"background-color: #5cb7ec; color: #ffffff;\"><strong>This is part of the tutorial series on Building a WordPress Shortcodes Library, where we build shortcodes for common functionalities necessary for WordPress core features, theme features as well as plugin features.<\/strong><\/p>\n<!-- \/wp:paragraph --><!-- wp:heading -->\n<h2>Building the Shortcode<\/h2>\n<!-- \/wp:heading --><!-- wp:paragraph -->\n<p>The shortcode created in this section will allow you to add any of the existing menus on your WordPress site to a post or page. The first step in this process is to identify a location for adding the code. We have 3 options for adding the code for the shortcode.<\/p>\n<!-- \/wp:paragraph --><!-- wp:list {\"ordered\":true} -->\n<ol>\n<li>Using a custom plugin<\/li>\n<li>Using the <code>functions.php<\/code> file of a child theme<\/li>\n<li>Using the <code>functions.php<\/code> file of the theme (not recommended as the changes will be wiped out by the theme update)<\/li>\n<\/ol>\n<!-- \/wp:list --><!-- wp:paragraph -->\n<p>In this tutorial, we are going to use custom plugin to add the code for the shortcode. If you are not faimilier with creating WordPress custom plugins, use the follwing video to create a plugin and install it.<\/p>\n<!-- \/wp:paragraph --><!-- wp:core-embed\/youtube {\"url\":\"https:\/\/www.youtube.com\/watch?v=Cuq5V6tCFak\",\"type\":\"video\",\"providerNameSlug\":\"youtube\",\"align\":\"center\",\"className\":\"wp-embed-aspect-16-9 wp-has-aspect-ratio\"} -->\n<figure class=\"wp-block-embed-youtube aligncenter wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\" style=\"width: 640px;\"><\/figure>\n<p>\u00a0<\/p>\n<!-- \/wp:paragraph -->\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fbed771 elementor-widget elementor-widget-video\" data-id=\"fbed771\" data-element_type=\"widget\" data-settings=\"{&quot;youtube_url&quot;:&quot;https:\\\/\\\/youtu.be\\\/LUvdNiyZd6c&quot;,&quot;video_type&quot;:&quot;youtube&quot;,&quot;controls&quot;:&quot;yes&quot;}\" data-widget_type=\"video.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div class=\"elementor-wrapper elementor-open-inline\">\n\t\t\t<div class=\"elementor-video\"><\/div>\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fa78f59 elementor-widget elementor-widget-text-editor\" data-id=\"fa78f59\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<!-- wp:paragraph --><!-- \/wp:paragraph --><!-- wp:core-embed\/youtube {\"url\":\"https:\/\/www.youtube.com\/watch?v=Cuq5V6tCFak\",\"type\":\"video\",\"providerNameSlug\":\"youtube\",\"align\":\"center\",\"className\":\"wp-embed-aspect-16-9 wp-has-aspect-ratio\"} -->\n<figure class=\"wp-block-embed-youtube aligncenter wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\" style=\"width: 640px;\"><\/figure>\n<p>Now, we can use the following steps to build the shortcode.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p><strong>Step 1<\/strong> &#8211; Add the following code to define the shortcode and default attributes.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<pre class=\"lang:php\">add_shortcode('sm_navigation_menu','sm_navigation_menu');\nfunction sm_navigation_menu($atts,$content){\n\n    $atts = shortcode_atts( array(\n        'menu_class' =&gt; 'menu',\n        'menu' =&gt; '',\n        'container' =&gt; 'div',\n        'container_class' =&gt; '',\n        'echo' =&gt; false\n    ), $atts );\n\n    \/\/ Step 2 Code \n}<\/pre>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p><strong>Step 2<\/strong>&#8211; Add the following code after the line <strong>\/\/ Step 2 Code<\/strong><\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<pre class=\"lang:php\">$content = wp_nav_menu(\n        array(                \n            'menu' =&gt; sanitize_text_field($atts['menu']),\n            'menu_class' =&gt; sanitize_text_field($atts['menu_class']),\n            'container'  =&gt; sanitize_text_field($atts['container']),\n            'container_class' =&gt; sanitize_text_field($atts['container_class']),\n            'echo' =&gt; false\n        )\n    );\n\nreturn $content;\n<\/pre>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p>We have to add the complete code to the main file of custom plugin or any other location discussed in the previous section. Now, the shortcode is ready to be used inside a post or page.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p>\u00a0<\/p>\n<!-- \/wp:paragraph --><!-- wp:heading -->\n<h2>Understanding the Code<\/h2>\n<!-- \/wp:heading --><!-- wp:paragraph -->\n<p>First, we added the shortcode using the built-in add_shortcode function. We have named the shortcode as sm_navigation_menu. In Step 1, we also defined the default shortcode attributes and values. Let&#8217;s take a look at the attributes and their functionality.<\/p>\n<!-- \/wp:paragraph --><!-- wp:list -->\n<ul>\n<li><strong>menu <\/strong>&#8211; this attribute is used to specify the menu. We can pass the ID, name or menu slug as the value.<\/li>\n<li><strong>menu_class<\/strong> &#8211; menu is generated as an unordered list. The value used for this attribute is assigned as the CSS class for the HTML\n<ul>tag of the menu.<\/ul>\n<\/li>\n<li><strong>container <\/strong>&#8211; this attribute defines the parent container element of the\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>tag. By default div is used as the value to wrap the list in a<\/ul>\n<\/li>\n<\/ul>\n<div>element.<\/div>\n<\/li>\n<li><strong>container_class<\/strong> &#8211; This value used for this attribute is assigned as the CSS class for the container tag of the menu.<\/li>\n<li><strong>echo <\/strong>&#8211; this attribute defines whether to return the generated menu or print directly to the browser. By default this value is set as TRUE and menu will be printed to browser.<\/li>\n<\/ul>\n<!-- \/wp:list --><!-- wp:paragraph -->\n<p>We have the ability to pass the values for these attributes using the shortcode. If a value is not provided for a specific attribute, the default value provided inside the array will be used. The shortcode_atts function combines the values passed through the shortcode attributes and uses the default values when an attribute is not specified.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p>In Step 2, we used the built-in wp_nav_menu function to load the menu based on the provided settings. This function supports various argument. You can view complete list of arguments of this function at <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_nav_menu\/\">https:\/\/developer.wordpress.org\/reference\/functions\/wp_nav_menu\/<\/a> .<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p>You have 4 configurable attributes to this shortcode called <strong>menu<\/strong>,<strong>menu_class<\/strong>, <strong>container <\/strong>and <strong>container_class<\/strong>. Apart from that, we set <strong>echo <\/strong>as <strong>false <\/strong>to assign the menu to a variable and return the menu from the shortcode.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p>Now, we are ready to start using the shortcode.<\/p>\n<!-- \/wp:paragraph --><!-- wp:heading -->\n<h2>Using the Navigation Menu Shortcode<\/h2>\n<!-- \/wp:heading --><!-- wp:paragraph -->\n<p>First, we need a navigation menu to display with this shortcode. Use the following steps to create a navigation menu and use the shortcode on a post or page.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p><strong>Step 1 <\/strong>&#8211; Login to the site and go to <strong>Appreance -&gt; Menus<\/strong> section in admin section to get a screen similar to the following.<\/p>\n<!-- \/wp:paragraph --><!-- wp:image {\"id\":7892,\"sizeSlug\":\"large\"} -->\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"480\" class=\"wp-image-7892\" src=\"https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_1-1024x480.png\" alt=\"\" srcset=\"https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_1-1024x480.png 1024w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_1-300x141.png 300w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_1-768x360.png 768w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_1.png 1345w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<!-- \/wp:image --><!-- wp:paragraph -->\n<p><strong>Step 2<\/strong> &#8211; Add a name for the menu and click the Create Menu link to get a screen similar to the following. We will be using <strong>Shortcode Menu<\/strong> as the name.<\/p>\n<!-- \/wp:paragraph --><!-- wp:image {\"id\":7893,\"sizeSlug\":\"large\"} -->\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"470\" class=\"wp-image-7893\" src=\"https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_2-1024x470.png\" alt=\"\" srcset=\"https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_2-1024x470.png 1024w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_2-300x138.png 300w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_2-768x352.png 768w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_2.png 1349w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<!-- \/wp:image --><!-- wp:paragraph -->\n<p><strong>Step 3<\/strong> &#8211; Add Posts, Pages or Custom Links from the <strong>Add menu items<\/strong> section. You can use the checkbox to select and click <strong>Add to Menu<\/strong> button to add each item to the menu.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p><strong>Step 4<\/strong> &#8211; Click <strong>Save Menu<\/strong> button to save the menu.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p><strong>Step 5<\/strong> &#8211; Click <strong>Add New<\/strong> sub menu item under <strong>Pages<\/strong> menu to create a new page.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p><strong>Step 6<\/strong> &#8211; Add the shortcode for the menu as shown in the following screenshot.<\/p>\n<!-- \/wp:paragraph --><!-- wp:image {\"id\":7895,\"sizeSlug\":\"large\"} -->\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"428\" class=\"wp-image-7895\" src=\"https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_3-1024x428.png\" alt=\"\" srcset=\"https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_3-1024x428.png 1024w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_3-300x125.png 300w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_3-768x321.png 768w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_3.png 1365w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<!-- \/wp:image --><!-- wp:paragraph -->\n<p><strong>Step 7<\/strong> &#8211; Click <strong>Publish <\/strong>button to save the Page.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p><strong>Step 8<\/strong> &#8211; Click the <strong>View Page<\/strong> button to view the menu inside the page as shown in the following screenshot.<\/p>\n<!-- \/wp:paragraph --><!-- wp:image {\"id\":7896,\"sizeSlug\":\"large\"} -->\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"473\" class=\"wp-image-7896\" src=\"https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_4-1024x473.png\" alt=\"\" srcset=\"https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_4-1024x473.png 1024w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_4-300x138.png 300w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_4-768x355.png 768w, https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_4.png 1341w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<!-- \/wp:image --><!-- wp:paragraph -->\n<p>In this case, we have passed menu name using menu attribute to load the menu. Apart from that, we have used <code>section<\/code> tag as the container instead of the default <code>div <\/code>element and used custom CSS classes for the menu and container. These classes can be used later to style the menu.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p>We have completed building and using the shortcode for the WordPress navigation menu inside posts and pages.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p>Let us know your comments and questions about this tutorial. Also you are welcome to request shortcodes for various functionality. We will provide future tutorials for the requested shortcodes.<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p>\u00a0<\/p>\n<!-- \/wp:paragraph --><!-- wp:paragraph -->\n<p>\u00a0<\/p>\n<!-- \/wp:paragraph -->\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Navigation menu is a built-in WordPress feature, implemented by the theme. We have the ability to add any number of navigation menus from the backend section of WordPress. However, default theme features don&#8217;t support displaying menus inside posts or pages. In this tutorial, we are going to build a shortcode for displaying a navigation menu<a href=\"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[48,47],"class_list":["post-8252","post","type-post","status-publish","format-standard","hentry","category-content","tag-shortcode","tag-wordpress-menu"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Building a WordPress Navigation Menu Shortcode for Posts and Pages - WP Expert Developer<\/title>\n<meta name=\"description\" content=\"Navigation menu is a built-in WordPress feature, implemented by the theme. We have the ability to add any number of navigation menus from the backend section of WordPress. However, default theme features don&#039;t support displaying menus inside posts or pages. In this tutorial, we are building a shortcode for displaying a navigation menu inside posts or pages. A shortcode based navigation menu is useful for adding a post or page specific menu instead of the common navigation in the header or footer of the site.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building a WordPress Navigation Menu Shortcode for Posts and Pages - WP Expert Developer\" \/>\n<meta property=\"og:description\" content=\"Navigation menu is a built-in WordPress feature, implemented by the theme. We have the ability to add any number of navigation menus from the backend section of WordPress. However, default theme features don&#039;t support displaying menus inside posts or pages. In this tutorial, we are building a shortcode for displaying a navigation menu inside posts or pages. A shortcode based navigation menu is useful for adding a post or page specific menu instead of the common navigation in the header or footer of the site.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/\" \/>\n<meta property=\"og:site_name\" content=\"WP Expert Developer\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-15T11:36:34+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-02-24T04:41:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_1-1024x480.png\" \/>\n<meta name=\"author\" content=\"nimeshrmr\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"nimeshrmr\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/\",\"url\":\"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/\",\"name\":\"Building a WordPress Navigation Menu Shortcode for Posts and Pages - WP Expert Developer\",\"isPartOf\":{\"@id\":\"https:\/\/www.wpexpertdeveloper.com\/#website\"},\"datePublished\":\"2021-02-15T11:36:34+00:00\",\"dateModified\":\"2021-02-24T04:41:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.wpexpertdeveloper.com\/#\/schema\/person\/e76e2df836fce88f31eb9636c2562875\"},\"description\":\"Navigation menu is a built-in WordPress feature, implemented by the theme. We have the ability to add any number of navigation menus from the backend section of WordPress. However, default theme features don't support displaying menus inside posts or pages. In this tutorial, we are building a shortcode for displaying a navigation menu inside posts or pages. A shortcode based navigation menu is useful for adding a post or page specific menu instead of the common navigation in the header or footer of the site.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.wpexpertdeveloper.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building a WordPress Navigation Menu Shortcode for Posts and Pages\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wpexpertdeveloper.com\/#website\",\"url\":\"https:\/\/www.wpexpertdeveloper.com\/\",\"name\":\"WP Expert Developer\",\"description\":\"WP\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wpexpertdeveloper.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wpexpertdeveloper.com\/#\/schema\/person\/e76e2df836fce88f31eb9636c2562875\",\"name\":\"nimeshrmr\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wpexpertdeveloper.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c62218fd01b8f6c2f0654a25980de950?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c62218fd01b8f6c2f0654a25980de950?s=96&d=mm&r=g\",\"caption\":\"nimeshrmr\"},\"url\":\"https:\/\/www.wpexpertdeveloper.com\/author\/nimeshrmr\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Building a WordPress Navigation Menu Shortcode for Posts and Pages - WP Expert Developer","description":"Navigation menu is a built-in WordPress feature, implemented by the theme. We have the ability to add any number of navigation menus from the backend section of WordPress. However, default theme features don't support displaying menus inside posts or pages. In this tutorial, we are building a shortcode for displaying a navigation menu inside posts or pages. A shortcode based navigation menu is useful for adding a post or page specific menu instead of the common navigation in the header or footer of the site.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/","og_locale":"en_US","og_type":"article","og_title":"Building a WordPress Navigation Menu Shortcode for Posts and Pages - WP Expert Developer","og_description":"Navigation menu is a built-in WordPress feature, implemented by the theme. We have the ability to add any number of navigation menus from the backend section of WordPress. However, default theme features don't support displaying menus inside posts or pages. In this tutorial, we are building a shortcode for displaying a navigation menu inside posts or pages. A shortcode based navigation menu is useful for adding a post or page specific menu instead of the common navigation in the header or footer of the site.","og_url":"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/","og_site_name":"WP Expert Developer","article_published_time":"2021-02-15T11:36:34+00:00","article_modified_time":"2021-02-24T04:41:03+00:00","og_image":[{"url":"https:\/\/www.wpexpertdeveloper.com\/wp-content\/uploads\/2020\/03\/menu_shortcode_1-1024x480.png"}],"author":"nimeshrmr","twitter_card":"summary_large_image","twitter_misc":{"Written by":"nimeshrmr","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/","url":"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/","name":"Building a WordPress Navigation Menu Shortcode for Posts and Pages - WP Expert Developer","isPartOf":{"@id":"https:\/\/www.wpexpertdeveloper.com\/#website"},"datePublished":"2021-02-15T11:36:34+00:00","dateModified":"2021-02-24T04:41:03+00:00","author":{"@id":"https:\/\/www.wpexpertdeveloper.com\/#\/schema\/person\/e76e2df836fce88f31eb9636c2562875"},"description":"Navigation menu is a built-in WordPress feature, implemented by the theme. We have the ability to add any number of navigation menus from the backend section of WordPress. However, default theme features don't support displaying menus inside posts or pages. In this tutorial, we are building a shortcode for displaying a navigation menu inside posts or pages. A shortcode based navigation menu is useful for adding a post or page specific menu instead of the common navigation in the header or footer of the site.","breadcrumb":{"@id":"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wpexpertdeveloper.com\/building-wordpress-shortcode-navigation-menu\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.wpexpertdeveloper.com\/"},{"@type":"ListItem","position":2,"name":"Building a WordPress Navigation Menu Shortcode for Posts and Pages"}]},{"@type":"WebSite","@id":"https:\/\/www.wpexpertdeveloper.com\/#website","url":"https:\/\/www.wpexpertdeveloper.com\/","name":"WP Expert Developer","description":"WP","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wpexpertdeveloper.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wpexpertdeveloper.com\/#\/schema\/person\/e76e2df836fce88f31eb9636c2562875","name":"nimeshrmr","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wpexpertdeveloper.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c62218fd01b8f6c2f0654a25980de950?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c62218fd01b8f6c2f0654a25980de950?s=96&d=mm&r=g","caption":"nimeshrmr"},"url":"https:\/\/www.wpexpertdeveloper.com\/author\/nimeshrmr\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wpexpertdeveloper.com\/wp-json\/wp\/v2\/posts\/8252"}],"collection":[{"href":"https:\/\/www.wpexpertdeveloper.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wpexpertdeveloper.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wpexpertdeveloper.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wpexpertdeveloper.com\/wp-json\/wp\/v2\/comments?post=8252"}],"version-history":[{"count":7,"href":"https:\/\/www.wpexpertdeveloper.com\/wp-json\/wp\/v2\/posts\/8252\/revisions"}],"predecessor-version":[{"id":8277,"href":"https:\/\/www.wpexpertdeveloper.com\/wp-json\/wp\/v2\/posts\/8252\/revisions\/8277"}],"wp:attachment":[{"href":"https:\/\/www.wpexpertdeveloper.com\/wp-json\/wp\/v2\/media?parent=8252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wpexpertdeveloper.com\/wp-json\/wp\/v2\/categories?post=8252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wpexpertdeveloper.com\/wp-json\/wp\/v2\/tags?post=8252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}