32 votes

Add an admin page, but don't show it on the admin menu

From the docs on add_submenu_page(), you see that you can hide your submenu link from a top level menu item to which it belongs be setting the slug (1st argument) to null: add_action( 'admin_menu', '...
  • 421
12 votes

Remove Categories / Tags From Admin Menu

If you want to completely remove categories and tags you can do so like this: // Remove Categories and Tags add_action('init', 'myprefix_remove_tax'); function myprefix_remove_tax() { ...
  • 661
8 votes

Is It Possible To Add Custom Post Type Menu As Another Custom Post Type Sub Menu

Our custom post type: $args['show_in_menu'] = false; register_post_type('custom_plugin_post_type', $args); Add him for existing Custom Post Type ("product" for example): $existing_CPT_menu = 'edit....
6 votes

How to add a child item to a menu element (using wp_nav_menu_objects)

The WordPress functions changed since the answers here in 2014. As of today (Version 4.6.1) this code will create a main menu named "My Menu" , main item and sub item. To run code just paste and ...
  • 715
6 votes
Accepted

Reorder custom submenu item

Got it, thanks to cjbj's help, I was able to get the final solution: add_filter( 'custom_menu_order', 'submenu_order' ); function submenu_order( $menu_order ) { # Get submenu key location based ...
6 votes
Accepted

Simple Navigation Walker – Wrapper-class around first sub-menu

To be honest, I don't really know why my solution works, but it does 😂 I based my snippet on this solution and tweaked the output to my needs: Custom nav walker with different output depending on ...
6 votes
Accepted

get_the_title() gets printed out twice

Your conditional is always true. To understand why, consider what happens in this function when there is no post parent: function get_top_ancestor_id() { global $post; // no parent so this ...
  • 53.9k
5 votes

Adding different classes to anchor in navigation menu

you can follow the below Steps : Step 1 : In the wp-admin, go to Appearance -> Menus,put the class on the menu item here "CSS Classes (optional)". If you can't see the "CSS Classes (optional)" in the ...
5 votes

Remove Categories / Tags From Admin Menu

You may also want to remove the meta boxes from the Post Creation page // REMOVE POST META BOXES function remove_my_post_metaboxes() { remove_meta_box( 'categorydiv','post','normal' ); // ...
  • 273
5 votes
Accepted

Add custom html to last sub-menu item

Ok, so it turns out that by default, $depth in the end_lvl() function starts at 0 when it's a submenu and increments as the depth gets greater. So we need to test if {$depth} is equal to 0 to apply it ...
  • 19.8k
5 votes

Add custom html to last sub-menu item

The filter on wp_nav_menu_items should be the way to do this. Run the following (just hack into the theme header.php temporarily: function add_last_nav_item($items, $args) { // if (!is_admin() &&...
  • 63.9k
4 votes
Accepted

How to add sub-menu to a menu generated by wp_nav_menu by using plugin

You can modify your menu by using walker. include('subMenu.php'); $menu = wp_nav_menu( array('menu' => 'YOUR-MENU-NAME','menu_class' => 'megamenu','walker' => new subMenu)); create a file ...
  • 176
4 votes

Order Admin sub-menu items?

I know I'm necro-posting but I recently had the same issue. Please note that I used Rao's solution on SO to get to this answer. Assuming your CPT is called "notes". /** * @see https://codex....
4 votes
Accepted

Admin: sub menu doesnt display under apperance when activate my themes

Most of those are controlled by your theme support. The functionality does not come for "free" with WordPress, you need to implement the actual code. Once you have put together the code for your theme ...
  • 1,731
4 votes
Accepted

Is there a way to keep a custom menu expanded when editing a custom post type?

I figured this out by putting the main menu slug into the show_in_menu key of the custom post type array like so: $args = array ( 'labels' => $labels, 'hierarchical' => FALSE, ...
4 votes
Accepted

Add class to top level menu item if it has multiple child levels

Not sure, but maybe something like this will work? Add to the functions.php. See explanation here. //This function is responsible for adding "my-parent-item" class to parent menu item's function ...
3 votes

how to only add a top-level admin menu without it creating a sub-level-menu

There's not really a good way to do this. Checkout the _wp_menu_output function. It's where all the work gets done for the menu output. See that $submenu_as_parent parameter and how it's used? Setting ...
3 votes

How to have custom menu Item CSS Classes for wp_page_menu() or wp_list_pages()

There is no good filter to add the CSS classes to the anchor (<a>) elements, but as you need it for CSS styling you can use the filter for the <li> elements. This filter is called ...
  • 3,296
3 votes

Reorder custom submenu item

The result you get is not surprising, given that you're directly manipulating a global variable. You're replacing $submenu with only the items with keys 10 and 41. If you want to follow this method ...
  • 13.8k
3 votes

Nav walker, bootstrap: Display 3rd level items under 2nd level

I solved this problem. follow these instructions..... Add script (function($){ $(document).ready(function(){ $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) { ...
3 votes
Accepted

How to give position to Submenu under custom post type

If you connect your functions with proper hooks your submenu page will be displayed after your post type and taxonomy. Take a look at my example: /** * Register event post type * * Function is ...
  • 2,392
3 votes
Accepted

Generate a Menu that displays all child pages of top level parent

Here is a function that will output the top level parent along with all of the children of the current page. Helpful menu classes are added to the output. E.g. page_item_has_children, ...
  • 17.1k
3 votes

How to highlight 1st level menu item based on actual page

Yes, very much possible and you don't even have to add classes yourself. If you're using wp_nav_menu, Wordpress adds classes for every case the specific nav item is in. I'll name the important classes ...
  • 426
3 votes

$pages = get_pages('child_of='.$post->ID); Why arguments are concatenated?

Indeed - in the get_pages() documentation we can see that it accepts either a string or an array as an argument. It does seem a little bit weird to call a function with the arguments concatenated into ...
  • 6,345
2 votes

How show sub menu only using wp_nav_menu()

I've made a free plugin which solves this problem! https://wordpress.org/plugins/wp-nav-menu-extended/ This plugin extends the native wp_nav_menu function and adds additional options: level : (...
2 votes

how to create a menu with all sub categories?

After many research I found a trustful useful solution, this class works well: class EntexAutoSubmenu { /** * Constructor */ function __construct(){ add_action('...
2 votes

Getting custom admin submenu item to highlight when its active

i found out that you also need to use html entities for your link. since you have add_submenu_page( 'edit.php?post_type=jobs', 'Active Jobs', 'Active Jobs', 'manage_options', '...
2 votes

Moving Categories submenu to Media, but still opens Posts menu

To add to what @brasofilo answered 3 years ago, this is what is necessary in the current menu system (WP v4.5.1). add_action( 'admin_head-edit-tags.php', 'modify_menu_highlight_wpse_43839' ); ...

Only top scored, non community-wiki answers of a minimum length are eligible