Skip to content

Instantly share code, notes, and snippets.

@isotrope
Created September 11, 2014 14:07
Show Gist options
  • Save isotrope/d8262366abb46a0e2001 to your computer and use it in GitHub Desktop.
Save isotrope/d8262366abb46a0e2001 to your computer and use it in GitHub Desktop.
Quickly thrown together menu management helper for Christopher Ross
/**
* Add a Delete button to menu items without needing to open them up.
*
* Untested.
*
* Use at your own risk!
*/
(function ($) {
function chrossMenuDeleter() {
$('.menu-item').each(function () {
var $this = $(this),
iID = parseInt($this.attr('id').replace('menu-item-', ''), 10);
$newButton = $('<a class="helper-remove" data-item-id="' + iID + '" style="display: inline-block; position: absolute; right: 0; z-index: 999; ">DeleteMe!</a>').prependTo($this);
});
}
function chrossMenuBindDelete() {
$('#menu-to-edit').one('click', '.helper-remove', function () {
wpNavMenu.removeMenuItem($('#menu-item-' + $(this).data('item-id')));
wpNavMenu.registerChange();
});
}
$(document).ready(function () {
chrossMenuDeleter();
chrossMenuBindDelete();
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment