64

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' => __( '...


25

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', ...


13

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'); }


9

Use a submenu page as parent slug. The admin menu has just two levels, so the imaginary third level will be hidden. Sample code, tested: add_action( 'admin_menu', 'wpse_73622_register_hidden_page' ); function wpse_73622_register_hidden_page() { add_submenu_page( 'options-writing.php', 'Hidden!', 'Hidden!', 'exists', ...


8

I put together the following class for myself. It will find the top nav parent of the current page, or you can give it a target top nav ID in the walker constructor. class Walker_SubNav_Menu extends Walker_Nav_Menu { var $target_id = false; function __construct($target_id = false) { $this->target_id = $target_id; } function ...


8

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


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

On the function to register a new custom post type can you set this CPT as Submenu to a exist menu item. Use the param show_in_menu A example: register_post_type( 'issue', apply_filters( 'wpit_register_issue_post_type', array( 'labels' => $issue_labels, 'rewrite' => $issue_rewrite, ...


7

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()); }


6

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', '...


6

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

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

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

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."'>"; } ...


5

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


5

I made this work using the Posts menus and the Draft status. It relies on jQuery to modify the list item classes. Adapt to work with your post type and URLs. This is the result: add_action( 'admin_menu', 'wpse_44270_menu_admin' ); add_action( 'admin_head-edit.php', 'wpse_44270_highlight_menu_item' ); function wpse_44270_menu_admin() { ...


5

The page template's filename is stored as a post meta with key '_wp_page_template', so basically you can use get_post_meta($post_id, '_wp_page_template', true); to get the template filename for the page with ID $post_id. You can also do the reverse (i.e. getting id from page template filename) using Custom Field Parameters in WP_Query or other wordpress ...


5

Add an admin menu separator Separators, if this question targets this, are the dividers of the admin menu that separate the menu into sections. Per default it's divided into a "publish" and an "administration" area. Plugin for the rescue Here's what we're going to have afterwards: A custom separator. I wrote a pretty simple plugin that I run as mu-...


5

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


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

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

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


4

This appears to be a CSS related issue. You need to clear:both your <li> elements which contain your <a href=links...> Make sure you apply that clear property to your sub-menu <li> elements only and not your top level parent items. Without knowing or seeing the exact theme you are working with, be it custom or not, I can't say for sure ...


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

I finally achieve it with this code in function.php // Front end only, don't hack on the settings page if ( ! is_admin() ) { // Hook in early to modify the menu // This is before the CSS "selected" classes are calculated add_filter( 'wp_get_nav_menu_items', 'display_lasts_ten_posts_for_categories_menu_item', 10, 3 ); } // Add the ten last posts of af ...


4

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-&...


4

3 ideas: Create the empty parent pages and use a redirect plugin to redirect all requests from these pages to the children. Inside the menu options page insert a custom link and link to the desired child page. At the top of your template - lets say page.php - test if children for this page exist and use wp_redirect() to skip this page and redirect to the ...


4

This would probably be better achieved using CSS. First, you hide all .children: .page_item .children { display: none; } Then, you show the current_page_item's children: .current_page_item .children { display: block; }


4

You could achieve this with a custom walker function, on your menu. a very simple example: class Walker_WPA82563_Submenu extends Walker_Nav_Menu { function end_el(&$output, $item, $depth=0, $args=array()) { if( 'Boats' == $item->title ){ $output .= '<ul><li>Dynamic Subnav</li></ul>'; } $...


4

Whenever in doubt about a WordPress function, consult the Codex: Function_Reference/remove_menu_page. The correct function is remove_submenu_page hooked into admin_menu. add_action( 'admin_menu', 'remove_submenu_wpse_82873' ); function remove_submenu_wpse_82873() { global $current_user; get_currentuserinfo(); // If user not Super Admin ...


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