Thanks Chip for this code snippet. It&#39;s excellent and elegant. And yet useful.<br><br><div class="gmail_quote">On 20 March 2013 03:26, Chip Bennett <span dir="ltr">&lt;<a href="mailto:chip@chipbennett.net" target="_blank">chip@chipbennett.net</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">By the way, I&#39;ll share this with the list, rather than in-ticket. As per the Codex, the best-practice implementation to add a &quot;parent&quot; class to wp_nav_menu() list items is to filter wp_nav_menu_objects. I recently used this method, myself:<div>

<br></div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><pre style="margin-top:0px;margin-bottom:0px;padding:0px;border:0px;font-size:12px;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;color:rgb(51,51,51);line-height:16px">
<div style="margin:0px;padding:0px 0px 0px 10px;border:0px"><span style="margin:0px;padding:0px;border:0px;font-weight:bold">function</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(153,0,0);font-weight:bold">oenology_add_menu_parent_class</span><span style="margin:0px;padding:0px;border:0px">(</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$items</span> <span style="margin:0px;padding:0px;border:0px">)</span> <span style="margin:0px;padding:0px;border:0px">{</span></div>

<div style="margin:0px;padding:0px 0px 0px 10px;border:0px"><br></div><div style="margin:0px;padding:0px 0px 0px 10px;border:0px">        <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$parents</span> <span style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span style="margin:0px;padding:0px;border:0px;font-weight:bold">array</span><span style="margin:0px;padding:0px;border:0px">();</span></div>

<div style="margin:0px;padding:0px 0px 0px 10px;border:0px">        <span style="margin:0px;padding:0px;border:0px;font-weight:bold">foreach</span> <span style="margin:0px;padding:0px;border:0px">(</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$items</span> <span style="margin:0px;padding:0px;border:0px;font-weight:bold">as</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$item</span> <span style="margin:0px;padding:0px;border:0px">)</span> <span style="margin:0px;padding:0px;border:0px">{</span></div>

<div style="margin:0px;padding:0px 0px 0px 10px;border:0px">                <span style="margin:0px;padding:0px;border:0px;font-weight:bold">if</span> <span style="margin:0px;padding:0px;border:0px">(</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$item</span><span style="margin:0px;padding:0px;border:0px;font-weight:bold">-&gt;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">menu_item_parent</span> <span style="margin:0px;padding:0px;border:0px;font-weight:bold">&amp;&amp;</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$item</span><span style="margin:0px;padding:0px;border:0px;font-weight:bold">-&gt;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">menu_item_parent</span> <span style="margin:0px;padding:0px;border:0px;font-weight:bold">&gt;</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,153,153)">0</span> <span style="margin:0px;padding:0px;border:0px">)</span> <span style="margin:0px;padding:0px;border:0px">{</span></div>

<div style="margin:0px;padding:0px 0px 0px 10px;border:0px">                        <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$parents</span><span style="margin:0px;padding:0px;border:0px">[]</span> <span style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$item</span><span style="margin:0px;padding:0px;border:0px;font-weight:bold">-&gt;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">menu_item_parent</span><span style="margin:0px;padding:0px;border:0px">;</span></div>

<div style="margin:0px;padding:0px 0px 0px 10px;border:0px">                <span style="margin:0px;padding:0px;border:0px">}</span></div><div style="margin:0px;padding:0px 0px 0px 10px;border:0px">
        <span style="margin:0px;padding:0px;border:0px">}</span></div><div style="margin:0px;padding:0px 0px 0px 10px;border:0px"><br></div><div style="margin:0px;padding:0px 0px 0px 10px;border:0px">
        <span style="margin:0px;padding:0px;border:0px;font-weight:bold">foreach</span> <span style="margin:0px;padding:0px;border:0px">(</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$items</span> <span style="margin:0px;padding:0px;border:0px;font-weight:bold">as</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$item</span> <span style="margin:0px;padding:0px;border:0px">)</span> <span style="margin:0px;padding:0px;border:0px">{</span></div>

<div style="margin:0px;padding:0px 0px 0px 10px;border:0px">                <span style="margin:0px;padding:0px;border:0px;font-weight:bold">if</span> <span style="margin:0px;padding:0px;border:0px">(</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,134,179)">in_array</span><span style="margin:0px;padding:0px;border:0px">(</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$item</span><span style="margin:0px;padding:0px;border:0px;font-weight:bold">-&gt;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">ID</span><span style="margin:0px;padding:0px;border:0px">,</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$parents</span> <span style="margin:0px;padding:0px;border:0px">)</span> <span style="margin:0px;padding:0px;border:0px">)</span> <span style="margin:0px;padding:0px;border:0px">{</span></div>

<div style="margin:0px;padding:0px 0px 0px 10px;border:0px">                        <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$item</span><span style="margin:0px;padding:0px;border:0px;font-weight:bold">-&gt;</span><span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">classes</span><span style="margin:0px;padding:0px;border:0px">[]</span> <span style="margin:0px;padding:0px;border:0px;font-weight:bold">=</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(221,17,68)">&#39;menu-item-parent&#39;</span><span style="margin:0px;padding:0px;border:0px">;</span> </div>

<div style="margin:0px;padding:0px 0px 0px 10px;border:0px">                <span style="margin:0px;padding:0px;border:0px">}</span></div><div style="margin:0px;padding:0px 0px 0px 10px;border:0px">
        <span style="margin:0px;padding:0px;border:0px">}</span></div><div style="margin:0px;padding:0px 0px 0px 10px;border:0px"><br></div><div style="margin:0px;padding:0px 0px 0px 10px;border:0px">
        <span style="margin:0px;padding:0px;border:0px;font-weight:bold">return</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(0,128,128)">$items</span><span style="margin:0px;padding:0px;border:0px">;</span>    </div>

<div style="margin:0px;padding:0px 0px 0px 10px;border:0px"><span style="margin:0px;padding:0px;border:0px">}</span></div><div style="margin:0px;padding:0px 0px 0px 10px;border:0px">
<span style="margin:0px;padding:0px;border:0px">add_filter</span><span style="margin:0px;padding:0px;border:0px">(</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(221,17,68)">&#39;wp_nav_menu_objects&#39;</span><span style="margin:0px;padding:0px;border:0px">,</span> <span style="margin:0px;padding:0px;border:0px;color:rgb(221,17,68)">&#39;oenology_add_menu_parent_class&#39;</span> <span style="margin:0px;padding:0px;border:0px">);</span></div>

</pre></div></blockquote></div><div><br></div><div>I would recommend this method rather than using jQuery, though I&#39;m not sure about it being *required*.</div></div></blockquote></div><div><br></div>-- <br>Sami Keijonen<br>
Fox Holding Oy<br><a href="mailto:sami.keijonen@foxnet.fi">sami.keijonen@foxnet.fi</a><br><a href="http://www.foxnet.fi">www.foxnet.fi</a>