• Resolved Michael Samson

    (@illuminice)


    Hello,

    I’m hoping you can help me with a very strange and annoying problem I’m having with a new site I’m building…

    For some reason I cannot disable the WordPress Admin Bar from being displayed on the front-end of the site, even with your plugin in use.

    I have tried just about everything, from disabling it via functions.php, and even trying some css solutions. The problem with simply hiding the bar via css is that it is still technically there, even if not visible. WordPress loads in a space at the top of the site within the main html tag when the admin bar is present.

    I’ve reached out to the theme author, and they’re not being too helpful. This is a new install, and I don’t believe any plugins are to blame. I’ve tested deactivating many plugins just to rule them out, and this hasn’t helped.

    Strangely enough the one user role not showing the admin bar is the administrator. All other user rules show the bar, no matter what the settings are in their user account, and despite any code I put in to prevent it from displaying.

    This is such a stupid problem I’m having, but I can’t seem to solve it. I’d greatly appreciate any help you can offer!

    ~ Michael

    https://www.ads-software.com/plugins/hide-admin-bar/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello

    Please add the below code in your theme function.php file it will helps you.

    add_action('after_setup_theme', 'remove_admin_bar');
    
    function remove_admin_bar() {
    
    if (!current_user_can('administrator') && !is_admin()) {
    
      show_admin_bar(false);
    
    }
    
    }

    Thread Starter Michael Samson

    (@illuminice)

    Hello,

    Thank you for the quick response…

    I added this to the functions.php file in my child theme and unfortunately it had no effect. I’ve actually tried many solutions like this already, and none of them have worked.

    Do you think this has something to do with the fact I’m trying to do this in the child theme? Keep in mind that I’m using this plugin as well, and it too isn’t working.

    ~ Michael

    Thread Starter Michael Samson

    (@illuminice)

    I just tried the following code which actually had an effect, finally…

    add_filter( ‘show_admin_bar’, ‘__return_false’ );
    remove_action( ‘wp_footer’, ‘wp_admin_bar_render’, 1000 );

    Here’s the strange part though…

    The first line which should make the admin bar invisible is having absolutely no effect. It was only when I added this second line that the admin bar finally disappeared.

    I learned about this at this post:
    https://wpsites.org/hide-admin-bar-wordpress-10473/

    I’m still seeing some artifacts of the bar however…

    In the css I am seeing this:

    html {
    margin-top: 32px !important
    }

    This is not anywhere in the theme’s css, or my own. It seems to be there automatically for the admin bar itself. This is having the effect of pushing the body section of my site further down, and it’s not easy to override this because it already has an !important on it. I wonder where this is really coming from.

    I can also see the class “admin-bar” being called for under my body tag. This may or may not be theme related.

    Sigh… what a pain for something that should be simple to remove!

    ~ Michael

    Thread Starter Michael Samson

    (@illuminice)

    It looks like I found the solution here…

    https://www.dfactory.eu/remove-disable-admin-bar/

    The code at the top of this post works! It is thorough, and covers all issues I was having with the admin bar, including the css issues. I was a little skeptical when I saw how aggressive this script was, but it really did the trick.

    I’ve actually removed the plugin now, as this script made it unnecessary.

    ~ Michael

    Thanks Michael for sharing this.. For some reason hide admin bar was not working any longer but dfactory code did the trick.

    Plugin Contributor Shelby DeNike

    (@sdenike)

    Hey Michael,

    Strange that my plugin was not disabling it, I have only seen that issue when another plugin was forcing it to be enabled and canceling out the simple code in this plugin.

    Glad you got it all working though, and sorry for the delayed response on this ??

    Shelby

    No way I can hide the toolbar for subscribers, even with the dfactory code it stays visible. I tried your plugin, edited that, tried another plugin (Shortcodes Actions & Filters) that contains a few other snippets that work well… Hiding in CSS leaves a white bar on top. Now I’m considering to make a child theme just for this native WordPress feature. I doubt if that will work.

    Thanks Michael for the sharing ! I had exactly the same problem and I wasted a lot of time doing tests and reading tutorials that all talked about show_admin_bar() when it absolutely does not work.

    You sharing was very helpfull for me.

    Thanks Michael! I’ve been going nuts trying to get other codes to work, and this was the first one that did.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Admin Bar Displaying for All Users Except Administrator’ is closed to new replies.