Skip to content

Instantly share code, notes, and snippets.

@trepmal
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trepmal/9691061 to your computer and use it in GitHub Desktop.
Save trepmal/9691061 to your computer and use it in GitHub Desktop.
Sample code - add menu item with pre-added classes (possibly useful if paired with custom walker that checks for a class and changes output accordingly)
<?php
/*
* Plugin Name: Linkless Menu Items
* Plugin URI:
* Description:
* Version:
* Author: Kailey Lampert
* Author URI:
* License: GPLv2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* TextDomain:
* DomainPath:
* Network:
*/
$linkless_menu_items = new Linkless_Menu_Items();
class Linkless_Menu_Items {
function __construct() {
add_action( 'admin_init', array( &$this, 'admin_init' ) );
add_action( 'admin_footer-nav-menus.php', array( &$this, 'admin_footer' ) );
}
function admin_init() {
add_meta_box( 'linkless_links', __( 'Linkless Links', 'linkless-links' ), array( &$this, 'add_meta_box' ), 'nav-menus', 'side', 'low' );
}
function add_meta_box() {
echo "<p><input type='text' name='linkless-link' class='linkless-link widefat' value='' /></p>";
?><p class="button-controls">
<span class="add-to-menu">
<input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu', 'linkless-links' ); ?>" id="submit-linkless-link" />
<span class="spinner"></span>
</span>
</p><?php
}
function admin_footer() {
?><script>
jQuery('#submit-linkless-link').click( function(ev) {
ev.preventDefault();
linklesslink = jQuery('.linkless-link');
label = linklesslink.val();
console.log( label );
wpNavMenu.addItemToMenu({
'-1': {
'menu-item-type': 'custom',
'menu-item-url': '#',
'menu-item-title': label,
'menu-item-classes': 'no-link' // custom classes added here
}
}, wpNavMenu.addMenuItemToBottom );
});
</script><?php
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment