Order Admin sub-menu items?

The filter ‘custom_menu_order’ will not work on the menu order because apply_filters in wp-admin/includes/menu.php supplies false as the filtered content. You can try changing false to $menu and the filter works grand. Since we obviously can’t touch the core, here’s how I got it to work: function custom_menu_order(){ global $submenu; $find_page=”edit.php”; $find_sub = ‘Post Tags’; … Read more

Add a .last class to the last in each ul.sub-menu

Put the following in your functions.php class SH_Last_Walker extends Walker_Nav_Menu{ function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) { $id_field = $this->db_fields[‘id’]; //If the current element has children, add class ‘sub-menu’ if( isset($children_elements[$element->$id_field]) ) { $classes = empty( $element->classes ) ? array() : (array) $element->classes; $classes[] = ‘has-sub-menu’; $element->classes =$classes; } // We don’t … Read more

Display only page specific sub menu items using Custom Walker

Here is a much simpler implementation: class UL_Submenu_Walker extends Walker_Nav_Menu { private $hidden = false; function start_lvl(&$output, $depth) { if($depth == 0) { $style = $this->hidden ? “” : “display:none;”; } $output .= “<ul class=\”submenu-“.$depth.”\” style=””.$style.””>”; } function start_el(&$output, $item, $depth, $args) { $class_names = $value=””; $classes = empty( $item->classes ) ? array() : (array) … Read more

Remove a menu item created by a plugin

function remove_submenu() { remove_submenu_page( ‘edit.php’, ‘edit-tags.php?taxonomy=faq-topic&post_type=question’ ); remove_submenu_page( ‘edit.php’, ‘edit-tags.php?taxonomy=faq-tags&post_type=question’ ); } add_action( ‘admin_menu’, ‘remove_submenu’, 999 ); Please read the Codex. remove_submenu_page() need two parameters and the right hook. And very important: Use a very, very, very high priority in your hook! If you use a low priority, your function will be executed before the … Read more

Custom menu walker: how can i check first item

Count the level 0 elements in a static variable in the method and add an extra class if you hit the third. Sample code: function start_lvl(&$output, $depth) { static $column = 1; $indent = str_repeat(“\t”, $depth); if ($depth > 0) { $output .= “\n$indent<ul class=”subsubmenu”>\n”; } else { $column += 1; $extra = 3 === … Read more

how to create a menu with all sub categories?

This depends on what kind of menu you are talking about: 1) If you are talking about “custom menus” (found in the Backend under Design -> Menus) you can do the following: Create a new function with the action hook add_category inside of this function, you can create a new post of type the menu … Read more

Add custom menu item using wp_nav_menu_items filter

I’ve created these two functions you may use to add custom items to a given menu item present in your menu (page, post, link…). In your case, you can add these function to your functions.php and call them like this: $menu_name=”Your Menu Name”; $name_of_menu_item_to_append_to = ‘My Account’; $id_of_menu_item_to_append_to = get_wp_object_id( $name_of_menu_item_to_append_to, ‘nav_menu_item’ ); $new_submenu_item = … Read more