Tag

admin

How to Hide the WordPress Admin Bar

By | Tutorial, WordPress | No Comments

The WordPress admin bar, or toolbar, can be really helpful but sometimes it gets in my way, especially when I’m trying a new design and having difficulty imagining what it looks like without a dark gray bar running across the top.

For most people, with a single WordPress install, the solution is simply a matter of going into your profile and unchecking “Show Toolbar when viewing site”. But what if you’re running WordPress multisite? Unchecking that box removes the toolbar across your entire network when you only wanted to hide the toolbar on the new site you’re designing.

Sometimes I require a password for front-end content but there’s no need to grant access to the admin/dashboard, or frankly for them to even know it exists, so I’d rather not confuse them with a pointless toolbar.

Thankfully, as with most functionality in WordPress, there’s a pretty easy way to tell the admin bar to go away.

  1. Write a function which hooks into the “after_setup_theme” action.
    • Hooking into this action is important because it allows us to also remove the styles and scripts that WordPress enqueues for the admin bar. If they are not removed, then there will still be a space at the top of your page for the bar and that’s not very helpful.
  2. Inside your function, call the WordPress function, show_admin_bar() and pass just one parameter: false

There’s obviously a wide variety of scenarios for when and where to hide your admin bar, but hopefully the following examples will give you a good groundwork. This code will, most likely, go in your functions.php file.

Always Hide The Admin Bar

If you want to hide the admin bar for good, no matter who’s looking at the site, the code is pretty simple.

add_action( 'after_setup_theme', 'my_website_remove_admin_bar' );
function my_website_remove_admin_bar() {
   show_admin_bar( false );
}

Hide the Admin Bar If The User Doesn’t Have Access To The Admin/Dashboard

If you want to hide the admin bar from users who don’t have access to the admin/dashboard, then check their user capabilities. The capability to “read” is what allows access to the administration panel.

add_action( 'after_setup_theme', 'my_website_remove_admin_bar' );
function my_website_remove_admin_bar() {
   
   // if the user cannot "read", then they cannot access the admin/dashboard
   if ( ! current_user_can( 'read' ) )
      show_admin_bar( false );

}

Hide The Admin Bar on Specific Multisite Sites

If you want to hide the admin bar on specific sites on your multisite network, use the global $blog_id variable in your logic. The global $blog_id variable contains the ID of which site is currently being viewed.

add_action( 'after_setup_theme', 'my_website_remove_admin_bar' );
function my_website_remove_admin_bar() {
   
   // access the global variable
   global $blog_id;

   // remove the admin bar for one site
   if ( 3 == $blog_id )
      show_admin_bar( false );

   // remove the admin bar from multiple sites
   if ( in_array( $blog_id, array( 3, 5, 8, 10 ) ) )
      show_admin_bar( false );

}

Hide The Admin Bar on Specific Pages

Using WordPress conditional tags allows you to easily hide the admin bar on specific sections, or pages, of your site.

add_action( 'after_setup_theme', 'my_website_remove_admin_bar' );
function my_website_remove_admin_bar() {

   // hide the admin bar on your main page
   if ( is_home() )
      show_admin_bar( false );

   // hide the admin bar on your page with the title of 'About Me'
   if ( is_page( 'About Me' )
      show_admin_bar( false );

   // hide the admin bar on any taxonomy archive page
   if ( is_tax() )
      show_admin_bar( false );

}

CPT-onomies Update: Version 1.3 (MULTISITE!)

By | CPT-onomies, Plugins, Uncategorized, WordPress | 3 Comments
Download CPT-onomiesCPT-onomies Documentation

I’m pretty excited about this update and multisite compatibility is the reason why! As someone who manages a pretty vast multisite network, I think WordPress multisite is awesome and hope others find this new functionality useful as well.

But version 1.3 didn’t present itself solely bearing the fruits of multisite. Here’s the full list of improvements:

  • Added multisite custom post type manager.
  • Added setting to assign meta box format, i.e. autocomplete, checklist or dropdown.
  • Added “Show Admin Column” to the CPT-onomy settings.
    • This is a new register_taxonomy() setting as of WordPress 3.5.
    • Before, CPT-onomies added the column itself but will now hook into this new core taxonomy functionality.
    • I will retain backwards compatability for a little while.
  • Deprecated the ability to make the CPT-onomy admin columns sortable in order to align with new, core WP taxonomy admin column functionality.
    • The new core WordPress taxonomy admin columns are not sortable so, therefore, I’ve removed the column sort functionality from the plugin.
  • Deprecated the ‘custom_post_type_onomies_add_cpt_onomy_admin_sortable_column’ filter.
    • Before, you could use this filter to turn off the column sortability. Now, with sorting gone, there’s no need to have the filter.
  • Added support for the “Gravity Forms + Custom Post Types” plugin.
    • This particular feature was commissioned by a user and will allow you to create CPT-onomy relationships when you use a Gravity Forms form to create a custom post type post.
  • Added the ability to only include/assign specific terms by passing term IDs to a filter.
    • Like the previously added “exclude” filter, this filter allows you to designate that you only want specific CPT-onomy term(s) to be allowed to be assigned.
  • Added wp_set_post_terms() to the CPT-onomy class.

Hope you the enjoy the update. I already have ideas for the next round! And, as always, please let me know if you have any questions or find any bugs! Thanks!