Removing X from Side Menu and Top Menu in Admin Area

Hi,

I would love to know how to remove the “X” from the Top Bar and Side bar in the admin area for all roles other than admin.

Any idea on how to that that?

http://www.sayfish.ie/wp-content/uploads/2017/07/Screen-Shot-2017-07-25-at-17.24.11.png

Many Thanks

Aaron

Hi There,

Please add the following code under functions.php file locates in your child theme:

function admin_style() {
	if( current_user_can( 'administrator' ) ){
	?>
	<style type="text/css">
		#wp-admin-bar-cs-main,
		#toplevel_page_x-addons-home {
			display: none;
		}
	</style>
	<?php
	}	
}
add_action('admin_enqueue_scripts', 'admin_style');

I tried this solution and it did not work for me. The X Launch option still shows up in non admin toolbars.

Any thoughts of what else I could try?

Thanks,
Curt

Hi again,

You can use the following plugin for this purpose https://wordpress.org/plugins/user-role-editor/

Cheers!

Are you sure? I bought this plugin at your recommendation but do not see where I can hide individual toolbar items by role. It has an option to hide the toolbar altogether but that is not what I want to do. I simply do not want the X to show up on the toolbar. I want the subscriber level to have a toolbar and see their avatar, comments, logout etc.

Hi again,

It was a free plugin, you didn’t have to buy it. You just needed to install it. However to remove the “X” and it’s menu just replace the previously given code with the following code in your Child Theme’s functions.php file

function admin_style() {
	if( !current_user_can( 'administrator' ) ){
	?>
	<style type="text/css">
		#wp-admin-bar-cs-main,
		#toplevel_page_x-addons-home {
			display: none;
		}
	</style>
	<?php
	}	
}
add_action('admin_enqueue_scripts', 'admin_style');

Hope this helps!

No problem on the plugin. It appeared to be very limited functionality in the free version so I bought the Pro version. It looks useful and I will probably use it at some point. All looks good now.

Thanks,
Curt

Glad we could help.

Cheers!

Oops. I spoke too soon. It is actually still there. The session I looked at was a logged out session and it was not there but on my subscriber session it is still there. I edited the functions.php in the root directory of my x-child directory and cleared all caches but it is still there. I do not use cornerstone at all so if it is easier to send me code that hides it all together rather than just for admin that would be fine too. Maybe a shotgun approach will get rid of it. Very odd that anyone would want it to show up for non admin users anyway. All my other plugins that have toolbar shortcuts do not show up for non admin users.
Sorry for the false sense of hope.

Thanks,
Curt

I have also tried.

add_action( ‘admin_bar_menu’, ‘remove_wp_logo’, 999 );

function remove_wp_logo( $wp_admin_bar ) {
$wp_admin_bar->remove_node( ‘cs-main’ );
}

and

function shapeSpace_remove_toolbar_nodes($wp_admin_bar) {

$wp_admin_bar->remove_node('cs-main');

}
add_action(‘admin_bar_menu’, ‘shapeSpace_remove_toolbar_nodes’, 999);

Nothing seems to work. This is a pretty big deal as I would never want a non admin to have this show up in their toolbar.

Thanks,
Curt

This did the trick. Not sure it is the best way but it works.

#wp-admin-bar-avia, #wp-admin-bar-edit, #wp-admin-bar-cs-main{
    display:none;
}

Hi again,

Looks good to me as long as you’re using it inside the function we provided above.

Cheers!

Hi There,

Try this code:

function admin_style() {
  if( !current_user_can( 'administrator' ) ){
  ?>
  <style type="text/css">
    #wp-admin-bar-cs-main, .toplevel_page_x-addons-home {
    display:none;
}
  </style>
  <?php
  } 
}
add_action('admin_enqueue_scripts', 'admin_style');

See this: https://screencast-o-matic.com/watch/cbjv16IVFy

I was able to remove the “X” and the “Appearance” from the Side menu using the following, but I cannot, for the life of me, figure out how to remove the “X” at the top admin bar for everyone EXCEPT Administrators. I have now spent 3 hrs on several handfuls of posts and cannot get it to do anything.:

function admin_style() {
  if( !current_user_can( 'administrator' ) ){
  ?>
  <style type="text/css">
       #wp-admin-bar-cs-main,
       .toplevel_page_x-addons-home,
       #wp-admin-bar-avia,
       #wp-admin-bar-edit,
       #menu-appearance {
    display:none;
}
  </style>
  <?php
  }
}
add_action('admin_enqueue_scripts', 'admin_style');

Nevermind…

I reverted back to the original functions.php file and installed “Adminimize”

It did everything I need it to do via a plugin for both sidebar and admin top bar :grinning:

Glad you’ve sorted it out and thank you for sharing with us.

Cheers!