Hide admin bar to all users except admin wordpress

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

You can write this code in functions.php of your theme or in a plugin you create.

/**
* Disable admin bar on the frontend of your website
* for subscribers.
*/
function themeblvd_disable_admin_bar() {
if ( ! current_user_can(‘edit_posts’) ) {
add_filter(‘show_admin_bar’, ‘__return_false’);
}
}
add_action( ‘after_setup_theme’, ‘themeblvd_disable_admin_bar’ );

/**
* Redirect back to homepage and not allow access to
* WP admin for Subscribers.
*/
function themeblvd_redirect_admin(){
if ( ! defined(‘DOING_AJAX’) && ! current_user_can(‘edit_posts’) ) {
wp_redirect( site_url() );
exit;
}
}
add_action( ‘admin_init’, ‘themeblvd_redirect_admin’ );

0
WordPress 1 month 0 Answer 24 views 0

About Irfan

I love to Develop Websites, Applications and UI Design. I'm a Certified Developer, blogger and owner of Codexjunction.com. My friends call me WordPress Expert too. I like to learn and share technical stuff. For more info quick message me, I'll help you out.

Leave an answer

Captcha Click on image to update the captcha .

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>