How do I hide “Pages”, “Media”, “Comments”….for editor role?

/** remove editor dashboard menu */ define( ‘DISALLOW_FILE_EDIT’, true); function remove_menus(){ remove_menu_page( ‘index.php’ ); //Dashboard remove_menu_page( ‘jetpack’ ); //Jetpack* // remove_menu_page( ‘edit.php’ ); //Posts remove_menu_page( ‘upload.php’ ); //Media remove_menu_page( ‘edit.php?post_type=page’ ); //Pages remove_menu_page( ‘edit-comments.php’ ); //Comments remove_menu_page( ‘themes.php’ ); //Appearance remove_menu_page( ‘plugins.php’ ); //Plugins remove_menu_page( ‘users.php’ ); //Users remove_menu_page( ‘tools.php’ ); //Tools remove_menu_page( ‘options-general.php’ ); … Read more

Remove a class from a using Walker

You don’t need to use the Walker to remove classes from nav menu items. There is a filter, nav_menu_css_class which can be used to modify the classes on menu items. Filters the CSS class(es) applied to a menu item’s list item element. This, for example, would remove the classes from all menu items: add_filter( ‘nav_menu_css_class’, … Read more

Highlighting Active Page in Navigation when Viewing Child Pages

You’ve got a CSS problem, but you probably knew that already. There is a good post in this community “Highlight the parent menu-item when child menu item page is selected/loaded” that appears to offer a solution. But putting this into place in your site is easier said than done because of the rich variety (ahem) … Read more

Limit wp_nav_menu_objects() only to first-level menu items

depth argument, available in functions attached to wp_nav_menu_objects hook, refers to the max depth of rendered menu (how many menu levels will be visible on site). To change only first-level elements, you can check in the loop if the menu item has a parent. function change_menu($items) { if( !is_front_page() ) { foreach($items as $item) { … Read more

Increase wordpress menu Depth

depth must be an integer, try with this: <?php wp_nav_menu( array( ‘theme_location’ => ‘main_menu’, ‘container_id’ => ‘navbar-collapse-1’, ‘container_class’=> ‘navbar-collapse collapse navbar-right’, ‘menu_class’ => ‘nav navbar-nav’, ‘fallback_cb’ => false, ‘items_wrap’ => ‘%3$s’, ‘container’ => false, ‘depth’ => 6, ‘walker’ => new Bunch_Bootstrap_walker() ) ); ?> from codex: depth (int) How many levels of the hierarchy are … Read more

Prevent more than 2 level menus in dashboard?

I investigated the codebase a bit and found a globalMaxDepth option in wp-admin/js/nav-menu.js. When calling wpNavMenu.options.globalMaxDepth = 1 from the browser console in /wp-admin/nav-menus.php you are no longer able to nest more than one level per drag and drop. To achieve your goal you can now use admin_enqueue_scripts to add a JS file to your … Read more

add another html tag after li element in wp_nav_menu

When using wp_nav_menu() you can exclude the <ul> tag by setting the items_wrap to only include the list items (%3$s), then you can add your own <li> before or after that, and wrap it with <ul> yourself: <ul class=”footer-links”> <li> <p>copyright C 2021</p> </li> <?php wp_nav_menu( array( ‘menu’ => ‘Footer Navigation Menu’, ‘theme_location’ => ‘top_nav_menu’, … Read more