2

I know how to remove items from the left nav bar (hook into admin_menu and do global $menu; unset( $menu[ __( "Posts" ) ] ); for example). But it still shows a left nav bar (with nothing on it). I want the entire left nav bar gone.

I have tried this and it doesn't work:

//This doesn't work (in any hook, or plugin constructor)
show_admin_bar(false);

//This also doesn't work
add_filter('show_admin_bar', '__return_false');

What is the hook/function to do this?

7
  • It is a security topic? If no, hide it via Javascript - jQuery('#adminmenuback, #adminmenuwrap').remove();
    – bueltge
    Sep 28, 2015 at 10:46
  • @bueltge I would prefer a way to keep it from being written to the page.
    – Don Rhummy
    Sep 29, 2015 at 14:56
  • Which page, in your question was the goal to remove the completely menu on the left side?
    – bueltge
    Sep 29, 2015 at 19:09
  • @bueltge Every admin page if the user is an editor. I don't want them to have any left navigation.
    – Don Rhummy
    Sep 29, 2015 at 19:10
  • Maybe you can explain your requirements, your goal. I think, I understand not right. Do you remove items in the menu, right? And now you have items, there should also remove?
    – bueltge
    Sep 29, 2015 at 19:14

2 Answers 2

0

You could creatively use output caching to capture the adminbar and then discard it like so:

<?php
// this filter runs in menu-header.php L37 right before the admin menu is rendered
add_filter( 'parent_file', function( $parent_file ){
    ob_start();
    return $parent_file;
} );
// runs after the output
add_action( 'in_admin_header', function(){
    ob_clean(); // discard output
    echo '<div id="wpcontent">'; 
} );

Please do not actually consider using this in any production environment. It does not provide any security and it might break various things (for example the admin toolbar). I consider this an educational answer to the problem "how to use PHP output caching and WP filters to move remove stuff?". You are probably better off just using CSS.

1
  • Thank you for the idea but that's not really (as you state) a production-level concept. It could also be a bottleneck on RAM.
    – Don Rhummy
    Sep 30, 2015 at 16:51
0

If you look at the bottom of the menu-header.php file in the wp-admin folder, you will see that the admin menu is hard coded. There are no hooks that would allow you to disable it.

Another issue is that the #wpcontent div has a left margin (depending on the screen size), so even if you did strip out the admin menu code, the space it normally occupies would still be there.

1
  • Since the sidebar is hardcoded, OP's best shot at removing it might be to do it client side with JS. Oct 1, 2015 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.