Last active
August 29, 2015 13:57
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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