{"id":381,"date":"2010-06-29T18:39:50","date_gmt":"2010-06-29T16:39:50","guid":{"rendered":"http:\/\/kavdesign.net\/blog\/?p=381"},"modified":"2010-06-30T13:30:33","modified_gmt":"2010-06-30T11:30:33","slug":"how-to-add-an-id-for-each-menu-item-in-joomla-default-menu","status":"publish","type":"post","link":"https:\/\/www.kavdesign.net\/blog\/coding\/how-to-add-an-id-for-each-menu-item-in-joomla-default-menu\/","title":{"rendered":"How to add an id for each menu item in Joomla default menu?"},"content":{"rendered":"<p>Because Joomla menu adds an id only for the current menu item, this is the hack to add an id for all menu items:<\/p>\n<p><!--more--><br \/>\n<strong>For legacy vertical type of menu<\/strong> go to www.yoursite.com\/modules\/mod_mainmenu\/legacy.php<\/p>\n<p>On line 75 there is:<br \/>\n<code><br \/>\n} else {<br \/>\n$id = '' ;<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Just add this insted:<br \/>\n<code><br \/>\n} else {<br \/>\n$id = 'id=\"menu_item' . $mitem-&gt;id . '\"' ;<br \/>\n}<\/code><\/p>\n<p>This will add an unique id to the li tag.<\/p>\n<p><strong>For the default list menu<\/strong> go to www.youriste.com\/modules\/mod_mainmenu\/tmpl\/default.php<\/p>\n<p>On line 72 there is this code:<br \/>\n<code><br \/>\n} else {<br \/>\n$node-&gt;removeAttribute('id');<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Change it to this:<br \/>\n<code><br \/>\n} else {<\/code><\/p>\n<p>}<\/p>\n<p>This will add an unique id to the li tag.<\/p>\n<p>Also go to www.yoursite.com\/modules\/mod_mainmenu\/helper.php and find the following code on line 358:<\/p>\n<blockquote><p>switch ($tmp-&gt;browserNav)<br \/>\n{<br \/>\ndefault:<br \/>\ncase 0:<br \/>\n\/\/ _top<br \/>\n$data = &#8216;&lt;a href=&#8221;&#8216;.$tmp-&gt;url.'&#8221;&gt;&#8217;.$image.$tmp-&gt;name.'&lt;\/a&gt;&#8217;;<br \/>\nbreak;<\/p><\/blockquote>\n<p>And Change it to:<\/p>\n<blockquote><p>switch ($tmp-&gt;browserNav)<br \/>\n{<br \/>\ndefault:<br \/>\ncase 0:<br \/>\n\/\/ _top<br \/>\n$data = &#8216;&lt;a href=&#8221;&#8216;.$tmp-&gt;url.'&#8221; id=&#8221;menu_item&#8217;.$tmp-&gt;id.'&#8221;&gt;&#8217;.$image.$tmp-&gt;name.'&lt;\/a&gt;&#8217;;<br \/>\nbreak;<\/p><\/blockquote>\n<p>This will add an unique id to the a tag.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Because Joomla menu adds an id only for the current menu item, this is the hack to add an id for all menu items:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[9,29],"tags":[39,73,72],"class_list":["post-381","post","type-post","status-publish","format-standard","hentry","category-coding","category-joomla","tag-hack","tag-id","tag-menu","entry"],"_links":{"self":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/381","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/comments?post=381"}],"version-history":[{"count":11,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/381\/revisions\/384"}],"wp:attachment":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/media?parent=381"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/categories?post=381"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/tags?post=381"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}