3

I'm using the following code to hide the admin toolbar in the front end:
add_filter( 'show_admin_bar', '__return_false' );

But how do I hide this option in wp-admin?

enter image description here

1 Answer 1

4

Here's one way to hide it with CSS:

add_action( 'personal_options', function( $profileuser )
{
    ?><style>.show-admin-bar{ display: none;}</style><?php
} );

or rather place it within the <head>...</head> with:

add_action( 'admin_print_styles-user-edit.php', 'wpse_hide_admin_bar_settings' );
add_action( 'admin_print_styles-profile.php',   'wpse_hide_admin_bar_settings' );

function wpse_hide_admin_bar_settings()
{
    ?><style>.show-admin-bar{ display: none;}</style><?php
} 

You could perhaps add your own wpse_hide_admin_bar_settings filter if you need more control:

function wpse_hide_admin_bar_settings()
{
    if( (bool) apply_filters( 'wpse_hide_admin_bar_settings', false ) )
        echo '<style>.show-admin-bar{ display: none;}</style>';
} 

and then turn it off/on with:

add_filter( 'wpse_hide_admin_bar_settings', '__return_false' ); // show it
add_filter( 'wpse_hide_admin_bar_settings', '__return_true' );  // hide it
2
  • Thanks, that will work. Although one would think that when you disable this in the frontend, this option would at least be disabled backend.
    – Steven
    Feb 26, 2016 at 9:19
  • If I understand your comment, Steven: a) The "Show Toolbar" option is something a user might want to enable some times and disable other times. If unchecking the option in the dashboard removed it from the dashboard, there's no way to re-enable it. b) Quite curious: why do you want to remove this feature?
    – Jeff Cohan
    Feb 26, 2016 at 14:49

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.