Hide WordPress Adminbar for Untrusted User |
X

Congrats, You are Subscribed to Receive Updates.

Hide WordPress Adminbar for Untrusted User


Hide WordPress Adminbar for Untrusted User  is one of a security to avoid users to access your wp-admin from the front end.  You can simply disable it by using a following function. But remember the style-sheet of the adminbar is loaded unnecessarily and take some page load time which will reduce your site speed.

show_admin_bar( false );

just adding the above line of code on your  WordPress theme header help you to disable the adminbar. But the stylesheet still loads and which gives some added weight to load your site.

adminbar-hide
As like the above image, the two style sheets load always and take your site to load more and take time to render it. So now we are going to de-queue the style for not logged in users.  Add the following code on your theme “ functions.php ” file

hide-adminbar-thumb

The following function help you to disable adding style sheets for not loggend in users.

 ################################################################################
// Disable adminbar with disabling stylesheet. 
################################################################################
if(is_user_logged_in() ) {
	add_action  ( 'init',  'kv_adminbar_front_kill' );
	function kv_adminbar_front_kill() { 
		show_admin_bar( false );
		wp_dequeue_script('admin-bar');
		wp_dequeue_style('admin-bar'); 		 
	}
}

Likewise you can prevent loading based on your role and restrict to load for admins only.

 

 

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar