Title: Some shortcode items not getting id
Last modified: August 21, 2016

---

# Some shortcode items not getting id

 *  Resolved [21stcn](https://wordpress.org/support/users/21stcn/)
 * (@21stcn)
 * [12 years ago](https://wordpress.org/support/topic/some-shortcode-items-not-getting-id/)
 * Hi there,
 * I love this plugin. Thanks for all your hard work. I am using jquery to apply
   properties to the menu items outputted by the plugin in shortcode form. Everything
   works fine except some menu items don’t get an id attribute. Here is an example
   of the output:
 *     ```
       <li class="menu-item menu-item-type-post_type menu-item-object-page cmw-level-1 menu-item-419">
       <li id="menu-item-418" class="menu-item menu-item-type-post_type menu-item-object-page cmw-level-1 menu-item-418">
       <li class="menu-item menu-item-type-post_type menu-item-object-page cmw-level-1 menu-item-416">
       ```
   
 * You can see that only 1 items gets an id. I do have multiple versions of the 
   same menu in some content but the items not getting an ID seems random.
 * I have solved my problem by using a function to get the last class from the li:
   `.
   attr('class').split(' ').pop();`
 * but I am wondering if you are aware of this issue or know why it is happening
   as I would prefer not to have the extra code (and it is relying on the menu-item-###
   class being the last one)?
 * [https://wordpress.org/plugins/custom-menu-wizard/](https://wordpress.org/plugins/custom-menu-wizard/)

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [wizzud](https://wordpress.org/support/users/wizzud/)
 * (@wizzud)
 * [12 years ago](https://wordpress.org/support/topic/some-shortcode-items-not-getting-id/#post-4981829)
 * Okay, from my point of view the answer is straightforward : CMW doesn’t assign
   the item IDs, WordPress does. However, that probably doesn’t help you very much…
 * I think you will find that WordPress will only assign an ID if the ID that it
   intends assigning – in the format menu-item-[ID of the menu item] – has not already
   been used elsewhere on the page. So, for example, if you were to do jQuery(‘#
   menu-item-419’) on the page that produced the code pasted above, then you would
   get a result … but the element located would be somewhere else on the page. This
   is how WordPress avoids creating invalid duplicate IDs.
 * PS : If you are after the “menu-item-####” from the class, have you considered
   using a regex? …
 *     ```
       x = (el.className.match(/(^|\s)(menu-item-\d+)(\s|$)/) || [0,0,''])[2];
       ```
   
 *  Thread Starter [21stcn](https://wordpress.org/support/users/21stcn/)
 * (@21stcn)
 * [12 years ago](https://wordpress.org/support/topic/some-shortcode-items-not-getting-id/#post-4981830)
 * Ok, that makes sense. I have duplicate menu items on the same page so the ids
   not being unique sounds like the culprit.
 * Now that I understand the issue better I’ll use regex to make object selection
   by class more robust.
 * Thanks again (and for the regex)!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Some shortcode items not getting id’ is closed to new replies.

 * ![](https://ps.w.org/custom-menu-wizard/assets/icon-256x256.png?rev=1381901)
 * [Custom Menu Wizard Widget](https://wordpress.org/plugins/custom-menu-wizard/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-menu-wizard/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-menu-wizard/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-menu-wizard/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-menu-wizard/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-menu-wizard/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [21stcn](https://wordpress.org/support/users/21stcn/)
 * Last activity: [12 years ago](https://wordpress.org/support/topic/some-shortcode-items-not-getting-id/#post-4981830)
 * Status: resolved