76

Yes. When you register your post type you need to set show_in_menu to the page you would like it displayed on. Adding a custom post type as a sub-menu of Posts Here we set the "movies" post type to be included in the sub-menu under Posts. register_post_type( 'movies', array( 'labels' => array( 'name' => __( '...


31

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', 'register_my_custom_submenu_page' ); function register_my_custom_submenu_page() { add_submenu_page( null, 'My Custom Submenu Page', ...


16

add_action('admin_menu', 'my_remove_sub_menus'); function my_remove_sub_menus() { remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=category'); remove_submenu_page('edit.php', 'edit-tags.php?taxonomy=post_tag'); }


11

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() { register_taxonomy('category', array()); register_taxonomy('post_tag', array()); }


8

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.php?post_type=product'; $link_our_new_CPT = 'edit.php?post_type=custom_plugin_post_type'; add_submenu_page($existign_CPT_menu, 'SubmenuTitle', 'SubmenuTitle', '...


8

If I understand correctly, you want links with submenus to have an attribute of aria-haspopup. If this is correct, you should be able to do so using the nav_menu_link_attributes filter (WP 3.6 and above). You can also get around the necessity of having to write a custom Walker to check if an item has children by checking its css classes in the filter. ...


7

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( $...


6

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 saves in your functions.php file in your child theme. $menu_id = wp_create_nav_menu('My Menu'); $parent_item = wp_update_nav_menu_item($menu_id, 0, array( '...


6

Here is a solution I just came up with which doesn't use jQuery: There is a filter parent_file in wp-admin/menu-header.php which runs right before outputting the menu. The inline comment says: For plugins to move submenu tabs around. It is just a filter on the global variable $parent_file and I am not sure what it does but we will use this filter to ...


6

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 on slug global $submenu; $settings = $submenu['options-general.php']; foreach ( $settings as $key => $details ) { if ( $details[2] == '...


6

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 depth class sublevel_wrapper extends Walker_Nav_Menu { // add classes to ul sub-menus function start_lvl( &$output, $depth = 0, $args = array() ) { ...


6

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 doesn't run: // if($post->post_parent) { // $ancestors = array_reverse(get_post_ancestors($post->ID)); // return $ancestors[0]; // ...


5

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' ); // Categories Metabox remove_meta_box( 'tagsdiv-post_tag','post','normal' ); // Tags Metabox } add_action('admin_menu','remove_my_post_metaboxes');


5

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 menu item, then there is "Screen Option" in the right top of the screen and there are the options "CSS Class" under "Show advanced menu properties". Step 2: ...


5

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 only to the first set of submenus: function end_lvl( &$output, $depth, $args ) { if( 0 == $depth ) { $output .= '<div>the div that I ...


5

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() && $args->theme_location == 'accessories') { $items .= '<div>the div that I want to show only once</div>'; // } return $items; } ...


4

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.wordpress.org/Plugin_API/Filter_Reference/menu_order */ add_filter( 'custom_menu_order', 'change_note_submenu_order' ); /** * Change the submenu order for the Note ...


4

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 to support one of the features you can enable it with add_theme_support. for example, in functions.php: add_action( 'after_setup_theme', function () { ...


4

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, 'description' => $title . 's', 'supports' => array( 'title' ), 'show_ui' => TRUE, 'show_in_menu' => '...


4

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 add_menu_parent_class( $items ) { $parents = array(); foreach ( $items as $item ) { //Check if the item is a parent item if ( $item->menu_item_parent &...


4

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 you would need to do this (assuming there's nothing at key 11): $submenu['options-general.php'][11] = $submenu['options-general.php'][41]; unset ($submenu['...


4

Here some thing interesting for you STEP 1 add a script to header like below ( it's always better go for the enqueue method . i need some one to help me with properly adding the below script in WordPress way .jquery should run before the second script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"&...


3

At first glance, and without testing anything, the code you've got should work but I expect that you have a number of spurious </ul> in your markup. You need to do nearly the same thing for the end_lvl method. function end_lvl(&$output, $depth) { if($depth >= 2) { $output .= ''; } else { $output .= "</ul>"; } ...


3

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 subMenu.php in theme folder add below code. <?php class subMenu extends Walker_Nav_Menu { function end_el(&$output, $item, $depth=0, $args=array()) {...


3

You are definitely on the right track, but wp_nav_menu will output a menu with a lot of containers and classnames; to keep it semantic in the terms of Semantic UI, you'll be in good hands if you build the structure yourself. Get the name of the registered menu in the menu manager. Check register_nav_menu in your functions.php if you're unsure. This is for ...


3

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 that to false produces the result you want, but there's no filters to actually make that work. There is an open ticket on the matter, but no action has really ...


3

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 page_css_class, which is, natively, used solely in listing pages through wp_list_pages(). It filters the classes used for the li-tags. To use this filter, simply hook ...


3

I solved this problem. follow these instructions..... Add script (function($){ $(document).ready(function(){ $('ul.dropdown-menu [data-toggle=dropdown]').on('click', function(event) { event.preventDefault(); event.stopPropagation(); $(this).parent().siblings().removeClass('open'); $(this).parent().toggleClass('open'); ...


3

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, current_page_item, current_page_ancestor, etc. This solution is based on one of the examples in the documentation for wp_list_pages() and this answer here on WPSE, which ...


3

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 for Publications (amongst others), based on where you clicked hypothetically: Publications - This is now the selected item, and will get (amongst others) the ...


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