Skip to content

Instantly share code, notes, and snippets.

@michaeloeser
Created March 19, 2016 13:21
Show Gist options
  • Save michaeloeser/a0691a3d06b6d27ab02d to your computer and use it in GitHub Desktop.
Save michaeloeser/a0691a3d06b6d27ab02d to your computer and use it in GitHub Desktop.
Customize the WordPress Toolbar for non-admin Users
<?php
// Redirect to homepage after logout
add_action('wp_logout','go_home');
function go_home(){
wp_redirect( home_url() );
exit();
}
// Customize the toolbar for non admins
function change_toolbar($wp_toolbar) {
if ( !current_user_can( 'manage_options' ) ) {
$wp_toolbar->remove_node('wp-logo');
$wp_toolbar->remove_node('site-name');
$wp_toolbar->remove_node('search');
$wp_toolbar->remove_node('my-account');
$wp_toolbar->add_node(array(
'id' => 'loguserout',
'title' => '&rarr; Logout',
'href' => wp_logout_url( get_permalink() )
));
}
}
add_action('admin_bar_menu', 'change_toolbar', 999);
@michaeloeser
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment