Support » Fixing WordPress » Admin Toolbar not showing

  • chiefgyk

    (@chiefgyk)


    So I have been racking my head trying to get the toolbar to showup for logged in users and the best I have managed to do is make it appear for everyone who isn’t even logged in. with the code below… I am using the Kleo theme for reference and using a child of it

    So this worked, but showed it to everyone and I don’t want that… I added it to functions.php in all cases

    //Insert into functions.php
    // always show admin bar
    function pjw_login_adminbar( $wp_admin_bar) {
    	if ( !is_user_logged_in() )
    	$wp_admin_bar->add_menu( array( 'title' => __( 'Log In' ), 'href' => wp_login_url() ) );
    }
    add_action( 'admin_bar_menu', 'pjw_login_adminbar' );
    add_filter( 'show_admin_bar', '__return_true' , 1000 );

    tried also

    if ( ! current_user_can( 'manage_options' ) ) {
        show_admin_bar( false );
    }

    and

    function myplugin_remove_admin_bar() {
    	if ( ! current_user_can( 'publish_posts' ) ) {
    		show_admin_bar( false );
    	}
    }
    add_action( 'plugins_loaded', 'myplugin_remove_admin_bar' );

    Nothing seems to work. It has been enabled in the profiles as well

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi chiefgyk,

    The admin bar showing for logged in users only is default functionality so I assume the Kleo theme or a plugin is messing with it. Is your issue that it isn’t showing at all, or that it is showing for all users?

    If it is not showing at all you should be able to invoke it in your functions.php file (or a small plugin) by doing the following:

    
    function show_admin_bar_to_logged_in_users() {
      if ( ! current_user_can( 'edit_posts' ) ) {
        show_admin_bar( true );
      }
    }
    
    add_action('after_setup_theme', 'show_admin_bar_to_logged_in_users');
    

    This fires the function after the theme is initialized which checks whether the current user is at least a contributor (can edit posts) and sets the show_admin_bar function to true.

    Let me know how it goes.

    chiefgyk

    (@chiefgyk)

    My issue is that it’s not showing at all. I tried the code you mentioned and still nothing. So far the only thing that somewhat worked was this

    //Insert into functions.php
    // always show admin bar
    function pjw_login_adminbar( $wp_admin_bar) {
    	if ( !is_user_logged_in() )
    	$wp_admin_bar->add_menu( array( 'title' => __( 'Log In' ), 'href' => wp_login_url() ) );
    }
    add_action( 'admin_bar_menu', 'pjw_login_adminbar' );
    add_filter( 'show_admin_bar', '__return_true' , 1000 );

    However the issue with that is that everyone, even those not logged in can see it. I just need it available to administrators

    kmessinger

    (@kmessinger)

    You should hot have to do anything for this behavior.

    Rename your plugins folder plugins-hold and see if it works. If not switch to the twenty-sixteen theme.

    Alternatively, if you must use the plugins you currently have installed changing the code you previously used to the below should work. Note the removal of the exclamation mark before is_user_logged_in()

    
    //Insert into functions.php
    // always show admin bar
    function pjw_login_adminbar( $wp_admin_bar) {
    	if ( is_user_logged_in() )
    	$wp_admin_bar->add_menu( array( 'title' => __( 'Log In' ), 'href' => wp_login_url() ) );
    }
    add_action( 'admin_bar_menu', 'pjw_login_adminbar' );
    add_filter( 'show_admin_bar', '__return_true' , 1000 );
    
    kmessinger

    (@kmessinger)

    Do not change WordPress core files. Your changes will be over-written at each upgrade.

    If it is a plugin problem contact the plugin’s help forum or find a new plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Admin Toolbar not showing’ is closed to new replies.