Support » Plugins » Custom Menu Item Type

  • My specific site requires a linkless “divider/category header” item in the menu and I would hate to have to link with # or javascript:void to fake it and then look for that hack to apply styles. I am relatively new to WordPress but am very comfortable with PHP. I have successfully created the metabox on the Menu page but I’m having difficulty creating the custom menu item type and linking data from the box to it. How would I approach this issue? Any comments and suggestions would be greatly appreciated. Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • If i understand correctly, you want top nav item to be #, and sub-menu to be regular links? Do you use wordpress 3+ menu?
    When you go to your dashboard, Appearance, do you see menus tab?

    No, I’m sorry if I mislead you, that’s exactly what I want to avoid. The same way there is a Custom Links or Pages metabox on the side, I want to create a new metabox that says for example “Divider” and then when you click on the Add to Menu in the form which I’d have to create inside of the metabox, it would add a new item to the menu which instead of Custom or Page on the right would say my own custom class Divider for example and I would set up how to display a Divider in my theme. Is that at all possible without modifying the core?

    P.S. As I’ve said, I’ve got the first part covered, I did create the metabox and displays where it should. Code below(the display part is just copied from Custom Link).

    //handler for adding dividers
    function add_divider_function()
    	global $_nav_menu_placeholder, $nav_menu_selected_id;
    	$_nav_menu_placeholder = 0 > $_nav_menu_placeholder ? $_nav_menu_placeholder - 1 : -1;
    	$current_tab = 'create';
    	if ( isset( $_REQUEST['customlink-tab'] ) && in_array( $_REQUEST['customlink-tab'], array('create', 'all') ) ) {
    		$current_tab = $_REQUEST['customlink-tab'];
    	$removed_args = array(
    	<div class="customlinkdiv" id="customlinkdiv">
    			<input type="hidden" value="custom" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-type]" />
    		<p id="menu-item-name-wrap">
    				<label class="howto" for="custom-menu-item-name">
    					<span><?php _e('Title'); ?></span>
    					<input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Leave blank for empty divider'); ?>" />
    		<p class="button-controls">
    			<span class="add-to-menu">
    				<img class="waiting" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
    				<input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu" value="<?php esc_attr_e('Add a Divider to the Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" />
    	</div><!-- /.customlinkdiv -->
    //configure admin menus
    function configure_admin_menus()
    	add_meta_box('add-divider','Divider','add_divider_function','nav-menus','side', 'default');
    add_action( 'admin_head', 'configure_admin_menus', 99 );

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Menu Item Type’ is closed to new replies.