Skip to content

Instantly share code, notes, and snippets.

@EdenK
Last active February 13, 2024 10:09
Show Gist options
  • Save EdenK/46af4c46947902aea3afb380c9a6ab5b to your computer and use it in GitHub Desktop.
Save EdenK/46af4c46947902aea3afb380c9a6ab5b to your computer and use it in GitHub Desktop.
Wordpress: Javascript Hook / Event for menu item added
jQuery(document).ready(function($) {
/**
* Event trigger document#menu-item-added file nav-menu.js in the function addMenuItemToBottom
* @param {object} event
* @param {object} markup Menu item html object
*/
$(document).on('menu-item-added', function(event, markup) {
// If more than 1 items is added we will need to loop
$.each(markup, function(index, menuItem) {
// Check if its the html object becuase there is another object that we get when we adding more than 1
if(menuItem.id) {
// Do something
console.log(menuItem.id); // Equal to the menu item attribute id
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment