{"id":633,"date":"2019-12-18T14:12:13","date_gmt":"2019-12-18T13:12:13","guid":{"rendered":"https:\/\/awhitepixel.com\/?p=633"},"modified":"2020-03-28T21:54:11","modified_gmt":"2020-03-28T20:54:11","slug":"wordpress-menu-walkers-tutorial","status":"publish","type":"post","link":"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/","title":{"rendered":"Learn How to Write Menu Walkers for WordPress Menus"},"content":{"rendered":"\n<p>WordPress allows using so-called Walker classes for traversing and displaying elements in an hierarchical structure. In this post we&#8217;ll learn about how to create, implement and customize our own walker class to customize our menu output.<\/p>\n\n\n\n<p>The most known use of customization with Walker classes in WordPress is for menus, but in reality WordPress uses Walker classes for a whole bunch of cases, for example outputting taxonomy hierarchies, comment hierarchies, <code><a rel=\"noreferrer noopener\" aria-label=\"wp_list_pages (opens in a new tab)\" href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_list_pages\/\" target=\"_blank\">wp_list_pages<\/a>()<\/code> and <code><a rel=\"noreferrer noopener\" aria-label=\"wp_list_categories (opens in a new tab)\" href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_list_categories\/\" target=\"_blank\">wp_list_categories<\/a>()<\/code>. They all extend a general <code>Walker<\/code> class. We will extend the <code>Walker_Nav_Menu<\/code> which is used for menus in WordPress.<\/p>\n\n\n\n<p>Because we extend another class we need only add the functions we wish to override. If a function does not exist in our class, WordPress will run the parent class&#8217; (the class we extend) function instead. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparation<\/h2>\n\n\n\n<p>You can add your walker class in your plugin files, theme&#8217;s <code>function.php<\/code> or any PHP file included by <code>functions.php<\/code> (for cleaner code). You start by defining your class by a name of your choosing (make sure the class name is unique, and this includes possible class names in WordPress core!) extending <code>Walker_Nav_Menu<\/code>:<\/p>\n\n\n\n<pre class=\"prettyprint linenums\">class AWP_Menu_Walker extends Walker_Nav_Menu {\n\t\n}\n<\/pre>\n\n\n\n<p>In order to tell WordPress to use our walker, we define this in our <code><a rel=\"noreferrer noopener\" aria-label=\"wp_nav_menu (opens in a new tab)\" href=\"https:\/\/developer.wordpress.org\/reference\/functions\/wp_nav_menu\/\" target=\"_blank\">wp_nav_menu<\/a>()<\/code> calls. This function is responsible for outputting a menu and you probably has at least one in your theme for the main menu.<\/p>\n\n\n\n<p>In the argument array to <code>wp_nav_menu()<\/code> you add a new element with the key &#8216;walker&#8217; and creates a new instance of your walker class like so:<\/p>\n\n\n\n<pre class=\"prettyprint linenums faded\">wp_nav_menu([\n    'theme_location' =&gt; 'primary',\n    'menu_class' =&gt; 'main-menu',\n    'container' =&gt; 'nav',\n    'container_class' =&gt; 'header__main-nav',\n<span class=\"featured\">    'walker' =&gt; new AWP_Menu_Walker()<\/span>\n]);\n<\/pre>\n\n\n\n<p>If you refresh your site you should see no change. This is because our class does not override any of the parent&#8217;s functions, and thus WordPress simply runs the normal menu walker functions when outputting the menu, just like before we told it to use our walker. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Overview of functions we can override in <code>Walker_Nav_Menu<\/code><\/h2>\n\n\n\n<p>The following are functions you can add to your custom walker class to override the parenting class <code>Walker_Nav_Menu<\/code> funtions:<\/p>\n\n\n\n<p>The first four are functions that are simply responsible for outputting, and they all require you to append to a string &#8211; the first parameter variable. It&#8217;s important to know that you don&#8217;t <code>echo<\/code> anything out here, everything is supposed to be built up as a string.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">start_lvl<\/h3>\n\n\n\n<p>The function <code>start_lvl<\/code> is responsible for outputting the HTML for the start of a new level. In short it should output the starting <code>&lt;ul&gt;<\/code>. <\/p>\n\n\n\n<pre class=\"prettyprint\">function start_lvl(&amp;$output, $depth=0, $args=null) { }\n<\/pre>\n\n\n\n<p>The first parameter, <code>$output<\/code> &#8211; passed by reference, is the string you&#8217;ll append your output to. <code>$depth<\/code> is an integer signaling which level you&#8217;re at; 0 for top-level, 1 for direct child of top-level, and so on. <code>$args<\/code> is an object of all arguments provided in <code>wp_nav_menu()<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">end_lvl<\/h3>\n\n\n\n<p>The <code>end_lvl<\/code> function is responsible for outputting the HTML for the end of a level. This is usually just the closing <code>&lt;\/ul&gt;<\/code>.<\/p>\n\n\n\n<pre class=\"prettyprint\">function end_lvl(&amp;$output, $depth=0, $args=null) { }\n<\/pre>\n\n\n\n<p>The parameters are the exact same as for <code>start_lvl<\/code> above.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">start_el<\/h3>\n\n\n\n<p>This function is responsible for outputting each element&#8217;s HTML. In short it should output the starting <code>&lt;li&gt;<\/code> and the <code>&lt;a&gt;<\/code> tag with the link title inside. <\/p>\n\n\n\n<pre class=\"prettyprint\">function start_el(&amp;$output, $item, $depth=0, $args=null, $id=0) { }\n<\/pre>\n\n\n\n<p>The first argument, <code>$output<\/code>, is as usual the string you&#8217;ll append the output to. The second argument, <code>$item<\/code>, is the menu item object &#8211; and this is where you&#8217;ll fetch most of the data for outputting the menu item. If the menu link is a post menu item, you&#8217;d get the post object here. Regardless of menu type, you&#8217;ll also get some additional useful elements; such as <code>classes<\/code>, <code>url<\/code>, <code>title<\/code>, and <code>description<\/code>.<\/p>\n\n\n\n<p>The third argument, <code>$depth<\/code>, is an integer telling you which level we&#8217;re at. Level 0 is top-level, 1 is direct child of top-level, and so on. The fourth argument, <code>$args<\/code>, is an object of all arguments provided to <code>wp_nav_menu()<\/code>. The fifth parameter, <code>$id<\/code>, is the current menu item ID.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">end_el<\/h3>\n\n\n\n<p>The <code>end_el<\/code> function is responsible for outputting the closing of an element. Usually it would just output the <code>&lt;\/li&gt;<\/code> tag.<\/p>\n\n\n\n<pre class=\"prettyprint\">function end_el(&amp;$output, $item, $depth=0, $args=null) { }\n<\/pre>\n\n\n\n<p>The arguments for <code>end_el<\/code> are the same as <code>start_el<\/code> above except that the function doesn&#8217;t have the fifth parameter, <code>$id<\/code>. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">display_element<\/h3>\n\n\n\n<p>The function <code>display_element<\/code> is an inherited function from the general <code>Walker<\/code> class, and is the function responsible for traversing. This is the function that calls all of the above functions in turn. <\/p>\n\n\n\n<p>I&#8217;m including this here because in some cases, for example if you want to prevent traversing a whole branch, you&#8217;d use this function for that.<\/p>\n\n\n\n<pre class=\"prettyprint\">function display_element($element, &amp;$children_elements, $max_depth, $depth, $args, &amp;$output) { }\n<\/pre>\n\n\n\n<p>The first argument, <code>$element<\/code>, is the menu item object &#8211; this is what is passed down as <code>$item<\/code> in the above functions. The second argument, <code>$children_elements<\/code> &#8211; passed by reference, contains all child elements this function will traverse. <code>$max_depth<\/code>, the third argument, is an integer that signals how deep we should traverse, and the fourth argument, <code>$depth<\/code>, is the depth we&#8217;re currently at. The fifth argument, <code>$args<\/code>, is the arguments passed to the function that called the walker (for menus it would be the arguments provided to <code>wp_nav_menu()<\/code>), and the final argument, <code>$output<\/code> &#8211; passed by reference, is the output which is passed down as first argument in all of the above functions.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Modifying the output of each element<\/h2>\n\n\n\n<p>In the overview above you should see that the function <code>start_el()<\/code> is the one responsible for outputting the HTML for a single menu element. Let&#8217;s start by overriding this function in our walker class with a simple example.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example: preventing adding links for &#8216;#&#8217; elements<\/h3>\n\n\n\n<p>Let&#8217;s make sure that any &#8216;<code>#<\/code>&#8216; links gets a <code>&lt;span><\/code> element instead of a link tag, to avoid refreshing the page. <\/p>\n\n\n\n<pre class=\"prettyprint linenums\">class AWP_Menu_Walker extends Walker_Nav_Menu {\n\tfunction start_el(&amp;$output, $item, $depth=0, $args=[], $id=0) {\n\t\t$output .= \"&lt;li class='\" .  implode(\" \", $item-&gt;classes) . \"'&gt;\";\n\n\t\tif ($item-&gt;url &amp;&amp; $item-&gt;url != '#') {\n\t\t\t$output .= '&lt;a href=\"' . $item-&gt;url . '\"&gt;';\n\t\t} else {\n\t\t\t$output .= '&lt;span&gt;';\n\t\t}\n\n\t\t$output .= $item-&gt;title;\n\n\t\tif ($item-&gt;url &amp;&amp; $item-&gt;url != '#') {\n\t\t\t$output .= '&lt;\/a&gt;';\n\t\t} else {\n\t\t\t$output .= '&lt;\/span&gt;';\n\t\t}\n\t}\n}\n<\/pre>\n\n\n\n<p>We&#8217;ll start the element by appending a <code>&lt;li&gt;<\/code> tag to <code>$output<\/code>. We want to make sure that WordPress&#8217; default classes (for example &#8216;menu-item&#8217;, &#8216;menu-item-has-children&#8217; etc), as well as classes entered manually in Menu editor gets added to our list element. We glue the classes provided as an array in <code>$item-&gt;classes<\/code> using the PHP function <code><a rel=\"noreferrer noopener\" aria-label=\"implode (opens in a new tab)\" href=\"https:\/\/www.php.net\/manual\/en\/function.implode.php\" target=\"_blank\">implode<\/a>()<\/code> separating each element with a space.<\/p>\n\n\n\n<p>At line #5-9 and #13-17 we handle the conditional output of the wrapping element. We output a <code>&lt;a&gt;<\/code> tag, unless the element&#8217;s URL is &#8216;<code>#<\/code>&#8216; in which case we provide a <code>&lt;span&gt;<\/code> tag instead. At line #11 we simply output the link&#8217;s text, which resides in <code>$item-&gt;title<\/code>. <\/p>\n\n\n\n<p>This is all we need for making sure all menu elements that has &#8216;<code>#<\/code>&#8216; as URL isn&#8217;t clickable!<\/p>\n\n\n\n<p>If you are doing this in a styled theme, keep in mind that you might lose some styling if the theme has styled the <code>&lt;a><\/code> tag directly. You can solve this by changing the styling and possibly adding a class to the span element.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example: displaying menu item descriptions<\/h3>\n\n\n\n<p>As an example another thing you can do here is outputting the menu description. This exists, but is not activated as default. In WordPress Menu editor you need to click &#8220;Screen Options&#8221; in the top right, and check off for showing &#8220;Description&#8221;:<\/p>\n\n\n\n<div class=\"wp-block-image framed\"><figure class=\"aligncenter\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"387\" src=\"https:\/\/awhitepixel.com\/wp-content\/uploads\/2019\/12\/wp-menu-screen-options-1024x387.png\" alt=\"\" class=\"wp-image-635\" srcset=\"https:\/\/awhitepixel.com\/wp-content\/uploads\/2019\/12\/wp-menu-screen-options-1024x387.png 1024w, https:\/\/awhitepixel.com\/wp-content\/uploads\/2019\/12\/wp-menu-screen-options-300x113.png 300w, https:\/\/awhitepixel.com\/wp-content\/uploads\/2019\/12\/wp-menu-screen-options-768x290.png 768w, https:\/\/awhitepixel.com\/wp-content\/uploads\/2019\/12\/wp-menu-screen-options.png 1073w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>This allows the user to enter a description to each element. You can output this description in your walker class. Let&#8217;s say you only want to show description for the top-level items, as this is a part of your theme&#8217;s design. You can simply check if the <code>$item<\/code> has a description and if <code>$depth<\/code> is 0, like so:<\/p>\n\n\n\n<pre class=\"prettyprint linenums faded\">\t\t...\n\t\t$output .= $item-&gt;title;\n\n<span class=\"featured\">\t\tif ($depth == 0 &amp;&amp; !empty($item-&gt;description)) {\n\t\t\t$output .= '&lt;span class=\"description\"&gt;' . $item-&gt;description . '&lt;\/span&gt;';\n\t\t}<\/span>\n\t\t...\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example: Adding dropdown carets<\/h3>\n\n\n\n<p>A more common and useful example is adding a &#8220;caret&#8221;, an icon that signals that this menu item has a dropdown menu (has child elements). <\/p>\n\n\n\n<div class=\"wp-block-image framed\"><figure class=\"aligncenter\"><img decoding=\"async\" loading=\"lazy\" width=\"577\" height=\"85\" src=\"https:\/\/awhitepixel.com\/wp-content\/uploads\/2019\/12\/wp-menu-carets.png\" alt=\"\" class=\"wp-image-637\" srcset=\"https:\/\/awhitepixel.com\/wp-content\/uploads\/2019\/12\/wp-menu-carets.png 577w, https:\/\/awhitepixel.com\/wp-content\/uploads\/2019\/12\/wp-menu-carets-300x44.png 300w\" sizes=\"(max-width: 577px) 100vw, 577px\" \/><figcaption>Example of carets in action &#8211; behind &#8220;Blog&#8221; and &#8220;News&#8221;<\/figcaption><\/figure><\/div>\n\n\n\n<p>You&#8217;ll need to figure out your caret HTML output. In my case I&#8217;m outputting an <code>&lt;i&gt;<\/code> item with specific classes for a nice down arrow available by the <a rel=\"noreferrer noopener\" aria-label=\"Fontawesome (opens in a new tab)\" href=\"https:\/\/fontawesome.com\/\" target=\"_blank\">Fontawesome<\/a> library which provides thousands of icons. You also want to ensure this caret only outputs on elements that has children. The best way I&#8217;ve found to figure out if the current element has children, is by referencing the walker object (yes, which is our walker itself, but also the classes it extends!) in <code>$args<\/code>, and checking the boolean <code>has_children<\/code>. Outputting a caret is as simple as:<\/p>\n\n\n\n<pre class=\"prettyprint linenums\">if ($args-&gt;walker-&gt;has_children) {\n\t$output .= '&lt;i class=\"caret fa fa-angle-down\"&gt;&lt;\/i&gt;';\n}\n<\/pre>\n\n\n\n<p>The complete walker class would look like this:<\/p>\n\n\n\n<pre class=\"prettyprint linenums\">class AWP_Menu_Walker extends Walker_Nav_Menu {\n\tfunction start_el(&amp;$output, $item, $depth=0, $args=[], $id=0) {\n\t\t$output .= \"&lt;li class='\" .  implode(\" \", $item-&gt;classes) . \"'&gt;\";\n\n\t\tif ($item-&gt;url &amp;&amp; $item-&gt;url != '#') {\n\t\t\t$output .= '&lt;a href=\"' . $item-&gt;url . '\"&gt;';\n\t\t} else {\n\t\t\t$output .= '&lt;span&gt;';\n\t\t}\n\n\t\t$output .= $item-&gt;title;\n\n\t\tif ($item-&gt;url &amp;&amp; $item-&gt;url != '#') {\n\t\t\t$output .= '&lt;\/a&gt;';\n\t\t} else {\n\t\t\t$output .= '&lt;\/span&gt;';\n\t\t}\n\n\t\tif ($args-&gt;walker-&gt;has_children) {\n\t\t\t$output .= '&lt;i class=\"caret fa fa-angle-down\"&gt;&lt;\/i&gt;';\n\t\t}\n\t}\n}\n<\/pre>\n\n\n\n<p>And that&#8217;s all you need for ensuring your menu gets nice caret icons on parent elements and that &#8216;<code>#<\/code>&#8216; links won&#8217;t be clickable.<\/p>\n\n\n\n<p>If you want the caret icon to change, for example into an up arrow when the dropdown is active, you will need to add this with Javascript to your theme.<\/p>\n\n\n\n<p>As the examples above suggest, you can manipulate the output however you&#8217;d like, based on any conditionals. You can for example modify the output based on if a certain class is present (for example a class manually entered in Menu editor) by looking for the class in <code>$item-&gt;classes<\/code>, or you can manipulate (for example capitalize) the outputted item text provided in <code>$item-&gt;title<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Providing arguments to your walker through your <code>wp_nav_menu<\/code><\/h2>\n\n\n\n<p>I would like to mention another useful thing. Remember that $args contains all arguments provided to <code>wp_nav_menu()<\/code>. This includes for example <code>theme_location<\/code> and others, so if you can modify the output only for specific theme locations &#8211; for example main menu. But you can actually provide any custom arguments!<\/p>\n\n\n\n<p>Say you are outputting the same menu multiple times, for example one for desktop and again for mobile. Or you want your walker to manipulate the items only when they are output by <code>wp_nav_menu()<\/code> in your theme, and not when the menu is added through a widget? Perhaps you want your walker to handle the output differently in these cases? <\/p>\n\n\n\n<p>You can provide any custom arguments to <code>wp_nav_menu()<\/code>. As a simple example, I&#8217;ll add a boolean &#8216;<code>show_carets<\/code>&#8216; to the arguments to ensure that carets are added only in those cases I want them &#8211; instead of my walker class adding carets to <em>all<\/em> menus.<\/p>\n\n\n\n<pre class=\"prettyprint linenums faded\">wp_nav_menu([\n    'theme_location' =&gt; 'primary',\n    'menu_class' =&gt; 'main-menu',\n    'container' =&gt; 'nav',\n    'container_class' =&gt; 'header__main-nav',\n    'walker' =&gt; new AWP_Menu_Walker(),\n<span class=\"featured\">    'show_carets' =&gt; true<\/span>\n]);\n<\/pre>\n\n\n\n<p>Then I can simply change my caret-adding piece of code above (line #19-21) into checking whether or not <code>show_carets<\/code> is present and true in <code>$args<\/code>, like so:<\/p>\n\n\n\n<pre class=\"prettyprint linenums\">if ($args-&gt;show_carets &amp;&amp; $args-&gt;walker-&gt;has_children) {\n\t$output .= '&lt;i class=\"caret fa fa-angle-down\"&gt;&lt;\/i&gt;';\n}\n<\/pre>\n\n\n\n<p>You can add any arguments you&#8217;d like ensuring your walker only customizes the menus you want to. For example simple booleans for different cases, e.g. <code>is_mobile_menu<\/code>, or anything else you need.<\/p>\n\n\n\n<p>And that&#8217;s about it. Feel free to experiment, and let me know if you have any questions or suggestions below!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WordPress allows using so-called Walker classes for traversing and displaying elements in an hierarchical structure. In this post we&#8217;ll learn about how to create, implement and customize our own walker class to customize our menu output. The most known use of customization with Walker classes in WordPress is for menus, but in reality WordPress uses [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":639,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"hide_page_title":false,"footnotes":""},"categories":[20,3],"tags":[15],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Learn How to Write Menu Walkers for WordPress Menus - A White Pixel<\/title>\n<meta name=\"description\" content=\"In this post we&#039;ll learn about how to create, implement and customize our own walker class to customize our menu output in WordPress.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Learn How to Write Menu Walkers for WordPress Menus - A White Pixel\" \/>\n<meta property=\"og:description\" content=\"In this post we&#039;ll learn about how to create, implement and customize our own walker class to customize our menu output in WordPress.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"A White Pixel\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-18T13:12:13+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-03-28T20:54:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/awhitepixel.com\/wp-content\/uploads\/2019\/12\/featured-menus.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2000\" \/>\n\t<meta property=\"og:image:height\" content=\"1148\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"AWhitePixel\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"AWhitePixel\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/\"},\"author\":{\"name\":\"AWhitePixel\",\"@id\":\"https:\/\/awhitepixel.com\/#\/schema\/person\/35e73a52e02ff0446ec9cadae3dd4072\"},\"headline\":\"Learn How to Write Menu Walkers for WordPress Menus\",\"datePublished\":\"2019-12-18T13:12:13+00:00\",\"dateModified\":\"2020-03-28T20:54:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/\"},\"wordCount\":1638,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/awhitepixel.com\/#organization\"},\"keywords\":[\"menus\"],\"articleSection\":[\"Themes\",\"WordPress\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/\",\"url\":\"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/\",\"name\":\"Learn How to Write Menu Walkers for WordPress Menus - A White Pixel\",\"isPartOf\":{\"@id\":\"https:\/\/awhitepixel.com\/#website\"},\"datePublished\":\"2019-12-18T13:12:13+00:00\",\"dateModified\":\"2020-03-28T20:54:11+00:00\",\"description\":\"In this post we'll learn about how to create, implement and customize our own walker class to customize our menu output in WordPress.\",\"breadcrumb\":{\"@id\":\"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/awhitepixel.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Learn How to Write Menu Walkers for WordPress Menus\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/awhitepixel.com\/#website\",\"url\":\"https:\/\/awhitepixel.com\/\",\"name\":\"A White Pixel\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/awhitepixel.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/awhitepixel.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/awhitepixel.com\/#organization\",\"name\":\"A White Pixel\",\"url\":\"https:\/\/awhitepixel.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/awhitepixel.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/awhitepixel.com\/wp-content\/uploads\/2020\/07\/cta-fox-wordpress-computer-blue.png\",\"contentUrl\":\"https:\/\/awhitepixel.com\/wp-content\/uploads\/2020\/07\/cta-fox-wordpress-computer-blue.png\",\"width\":365,\"height\":302,\"caption\":\"A White Pixel\"},\"image\":{\"@id\":\"https:\/\/awhitepixel.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/awhitepixel.com\/#\/schema\/person\/35e73a52e02ff0446ec9cadae3dd4072\",\"name\":\"AWhitePixel\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/awhitepixel.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/54b82f3f4c246724797e2a5bfeffa27f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/54b82f3f4c246724797e2a5bfeffa27f?s=96&d=mm&r=g\",\"caption\":\"AWhitePixel\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Learn How to Write Menu Walkers for WordPress Menus - A White Pixel","description":"In this post we'll learn about how to create, implement and customize our own walker class to customize our menu output in WordPress.","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:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Learn How to Write Menu Walkers for WordPress Menus - A White Pixel","og_description":"In this post we'll learn about how to create, implement and customize our own walker class to customize our menu output in WordPress.","og_url":"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/","og_site_name":"A White Pixel","article_published_time":"2019-12-18T13:12:13+00:00","article_modified_time":"2020-03-28T20:54:11+00:00","og_image":[{"width":2000,"height":1148,"url":"https:\/\/awhitepixel.com\/wp-content\/uploads\/2019\/12\/featured-menus.jpg","type":"image\/jpeg"}],"author":"AWhitePixel","twitter_card":"summary_large_image","twitter_misc":{"Written by":"AWhitePixel","Est. reading time":"11 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/#article","isPartOf":{"@id":"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/"},"author":{"name":"AWhitePixel","@id":"https:\/\/awhitepixel.com\/#\/schema\/person\/35e73a52e02ff0446ec9cadae3dd4072"},"headline":"Learn How to Write Menu Walkers for WordPress Menus","datePublished":"2019-12-18T13:12:13+00:00","dateModified":"2020-03-28T20:54:11+00:00","mainEntityOfPage":{"@id":"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/"},"wordCount":1638,"commentCount":2,"publisher":{"@id":"https:\/\/awhitepixel.com\/#organization"},"keywords":["menus"],"articleSection":["Themes","WordPress"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/","url":"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/","name":"Learn How to Write Menu Walkers for WordPress Menus - A White Pixel","isPartOf":{"@id":"https:\/\/awhitepixel.com\/#website"},"datePublished":"2019-12-18T13:12:13+00:00","dateModified":"2020-03-28T20:54:11+00:00","description":"In this post we'll learn about how to create, implement and customize our own walker class to customize our menu output in WordPress.","breadcrumb":{"@id":"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/awhitepixel.com\/wordpress-menu-walkers-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/awhitepixel.com\/"},{"@type":"ListItem","position":2,"name":"Learn How to Write Menu Walkers for WordPress Menus"}]},{"@type":"WebSite","@id":"https:\/\/awhitepixel.com\/#website","url":"https:\/\/awhitepixel.com\/","name":"A White Pixel","description":"","publisher":{"@id":"https:\/\/awhitepixel.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/awhitepixel.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/awhitepixel.com\/#organization","name":"A White Pixel","url":"https:\/\/awhitepixel.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/awhitepixel.com\/#\/schema\/logo\/image\/","url":"https:\/\/awhitepixel.com\/wp-content\/uploads\/2020\/07\/cta-fox-wordpress-computer-blue.png","contentUrl":"https:\/\/awhitepixel.com\/wp-content\/uploads\/2020\/07\/cta-fox-wordpress-computer-blue.png","width":365,"height":302,"caption":"A White Pixel"},"image":{"@id":"https:\/\/awhitepixel.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/awhitepixel.com\/#\/schema\/person\/35e73a52e02ff0446ec9cadae3dd4072","name":"AWhitePixel","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/awhitepixel.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/54b82f3f4c246724797e2a5bfeffa27f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/54b82f3f4c246724797e2a5bfeffa27f?s=96&d=mm&r=g","caption":"AWhitePixel"}}]}},"_links":{"self":[{"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/posts\/633"}],"collection":[{"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/comments?post=633"}],"version-history":[{"count":9,"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/posts\/633\/revisions"}],"predecessor-version":[{"id":1155,"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/posts\/633\/revisions\/1155"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/media\/639"}],"wp:attachment":[{"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/media?parent=633"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/categories?post=633"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/awhitepixel.com\/wp-json\/wp\/v2\/tags?post=633"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}