Home » Functions » show_admin_bar

Function Name: show_admin_bar

The show_admin_bar() function is a WordPress function that is used to display or hide the admin bar at the top of the page for logged-in users. The admin bar includes links to various WordPress functions such as adding new posts, editing your profile, and logging out.

By default, the admin bar is visible to all logged-in users. However, there may be instances where you want to hide it for certain users or on certain pages of your website. This is where the show_admin_bar() function comes in handy.

The show_admin_bar() function takes a single parameter, $show, which is a boolean value that determines whether the admin bar should be displayed or hidden. If $show is set to true, the admin bar will be displayed. If $show is set to false, the admin bar will be hidden.

Here is an example of how to use the show_admin_bar() function to hide the admin bar for non-admin users:

function hide_admin_bar() {
  if (!current_user_can('administrator') && !is_admin()) {
add_action('after_setup_theme', 'hide_admin_bar');

In this example, the function hide_admin_bar() is used to determine whether the current user is an administrator. If the current user is not an administrator and is not accessing the admin panel, the show_admin_bar() function is called with a parameter of false, which hides the admin bar.

Overall, the show_admin_bar() function is a simple and effective way to control the visibility of the WordPress admin bar on your website.

Learn More on

Register an account to save your snippets or go Pro to get more features.