{"id":297,"date":"2025-09-30T05:59:35","date_gmt":"2025-09-30T05:59:35","guid":{"rendered":"https:\/\/mitalgoswami.in\/?p=297"},"modified":"2025-09-30T05:59:35","modified_gmt":"2025-09-30T05:59:35","slug":"how-to-create-menu-in-wordpress-theme-development","status":"publish","type":"post","link":"https:\/\/mitalgoswami.in\/?p=297","title":{"rendered":"how to create menu in wordpress theme development"},"content":{"rendered":"\n<p>In <strong>WordPress theme development<\/strong>, creating a custom menu involves <strong>registering the menu<\/strong>, <strong>displaying it in your theme<\/strong>, and optionally <strong>styling it with CSS<\/strong>. Here\u2019s a step-by-step guide:<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1. Register the Menu in <code>functions.php<\/code><\/h2>\n\n\n\n<p>In your theme\u2019s <code>functions.php<\/code>, register your custom navigation menu using <code>register_nav_menus()<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\/\/ Register a navigation menu\nfunction mytheme_register_menus() {\n    register_nav_menus(\n        array(\n            'primary_menu' =&gt; __( 'Primary Menu', 'mytheme' ),\n            'footer_menu'  =&gt; __( 'Footer Menu', 'mytheme' ),\n        )\n    );\n}\nadd_action( 'init', 'mytheme_register_menus' );\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>primary_menu<\/code> \u2192 A slug you\u2019ll use in the theme.<\/li>\n\n\n\n<li><code>Primary Menu<\/code> \u2192 The name shown in WordPress Dashboard.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2. Display the Menu in Your Theme<\/h2>\n\n\n\n<p>Where you want the menu to appear (commonly in <code>header.php<\/code> or <code>footer.php<\/code>), use:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nwp_nav_menu( array(\n    'theme_location' =&gt; 'primary_menu',\n    'menu_class'     =&gt; 'nav-menu',\n    'container'      =&gt; 'nav', \/\/ could be 'div' or false to remove\n) );\n?&gt;\n<\/code><\/pre>\n\n\n\n<p>This will output an HTML <code>&lt;ul&gt;<\/code> list of menu items that you can style.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3. Add a Menu in WordPress Dashboard<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to <strong>Appearance \u2192 Menus<\/strong> in the WP Admin.<\/li>\n\n\n\n<li>Create a new menu and add pages, posts, or custom links.<\/li>\n\n\n\n<li>Assign the menu to <strong>Primary Menu<\/strong> (the one you registered).<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4. Optional \u2013 Add CSS for Styling<\/h2>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.nav-menu {\n  list-style: none;\n  display: flex;\n  gap: 20px;\n}\n\n.nav-menu li a {\n  text-decoration: none;\n  color: #333;\n}\n\n.nav-menu li a:hover {\n  color: #0073aa;\n}\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u2705 Now you have a working custom menu in your theme.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In WordPress theme development, creating a custom menu involves registering the menu, displaying it in your theme, and optionally styling it with CSS. Here\u2019s a step-by-step guide: 1. Register the Menu in functions.php In your theme\u2019s functions.php, register your custom navigation menu using register_nav_menus(). 2. Display the Menu in Your Theme Where you want the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,2],"tags":[],"class_list":["post-297","post","type-post","status-publish","format-standard","hentry","category-unit-5","category-wordpress"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297"}],"version-history":[{"count":1,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions"}],"predecessor-version":[{"id":298,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions\/298"}],"wp:attachment":[{"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitalgoswami.in\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}