Search code examples
wordpresssubmenu

Different IDs For each Wordpress Submenu?


Does anyone know of a way to add a unique ID to each submenu wordpress Generates? As of now, WP generates:

<ul class="sub-menu"></ul>

Ideally, I'd like it to generate

<ul class="sub-menu" id="radio"></ul>

So that I can assign a different style to each sub menu generated via css.

Any help is appreciated.


Solution

  • This may not be the best way, but it did the trick for me..

    <script>
    $(function(){
        var i =0;
     $('ul.sub-menu').addClass (function(idx) {
    
         return "item-" + idx;
     });
     });
     </script>
    

    It appends the class item-0, item-1, etc to each sub-menu it finds.