How to Customize WordPress Admin Area

Published on : December 17, 2016

Author:

Category: Wordpress


In many cases, we need to change the WordPress admin area. Many of us use CSS but I think it’s not ideal where security issues are a big concern and if you try to change the WordPress core code it will be wiped out when you update the WordPress to a newer version. So I would like to share some tips to get your WordPress admin customized

Adding admin color scheme

// custom admin color scheme
wp_admin_css_color( 'colorscheme', __('Color Scheme'), get_bloginfo('template_directory').'/css/css.css', array('#07273E', '#14568A', '#D54E21', '#2683AE') );
// ends

 

if you want to change everyone’s color scheme to admin’s default color scheme just use the following code

// set admin selected color scheme to all user
if( is_user_logged_in() ) {
	$admin_color_scheme = get_user_meta( 1, 'admin_color', true );
	$user_results = get_users();
	foreach ( $user_results as $single_user ) {
		update_user_meta( $single_user->ID, 'admin_color', $admin_color_scheme );
	}
}
// ends

 

Remove toolbar menus and pages from admin area for other users

To remove admin menus and toolbar menus for other users, for changing the admin logo, URL, text and removing user roles just use the code below. They are well commented so you will not face a problem using these.

// remove page and toolbar options if user is not admin
$user = wp_get_current_user();
if ( in_array( 'superuser', (array) $user->roles ) || in_array( 'sales', (array) $user->roles ) ) {
    function remove_menus(){
      
      remove_menu_page( 'index.php' );                  //Dashboard
      remove_menu_page( 'edit.php' );                   //Posts
      remove_menu_page( 'upload.php' );                 //Media
      remove_menu_page( 'edit.php?post_type=page' );    //Pages
      remove_menu_page( 'edit-comments.php' );          //Comments
      remove_menu_page( 'themes.php' );                 //Appearance
      remove_menu_page( 'plugins.php' );                //Plugins
      remove_menu_page( 'users.php' );                  //Users
      remove_menu_page( 'tools.php' );                  //Tools
      remove_menu_page( 'options-general.php' );        //Settings
      
    }
    add_action( 'admin_menu', 'remove_menus' );

  // remove wordpress logo and the menu from the admin panel
	function remove_logo_and_submenu() {
		global $wp_admin_bar;
		$wp_admin_bar->remove_menu('wp-logo');
		$wp_admin_bar->remove_menu('about');
		$wp_admin_bar->remove_menu('wporg');
		$wp_admin_bar->remove_menu('documentation');
		$wp_admin_bar->remove_menu('support-forums');
		$wp_admin_bar->remove_menu('feedback');
		$wp_admin_bar->remove_menu('comments');
		$wp_admin_bar->remove_node( 'new-post' );
	  	$wp_admin_bar->remove_node( 'new-link' );
	  	$wp_admin_bar->remove_node( 'new-media' );
	  	$wp_admin_bar->remove_node( 'new-content' );
	  	$wp_admin_bar->remove_node( 'site-name' );
	}
	add_action( 'wp_before_admin_bar_render', 'remove_logo_and_submenu', 999 );
	// ends

	// remove footer from wp-admin
	add_filter('admin_footer_text', 'kcr_remove_admin_footer_text', 1000);
	function kcr_remove_admin_footer_text($footer_text ='') {
	    return '';
	    // echo 'Developed by Your Name';
	}

	add_filter('update_footer', 'kcr_remove_admin_footer_upgrade', 1000);
	function kcr_remove_admin_footer_upgrade($footer_text ='') {
	    return '';
	}
	// ends

	// remove color scheme
	remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
	// ends
}
// ends

// custom admin login logo and url and alt text
function custom_login_logo() {
  echo '
h1 a {
 background-image: url(/images/logo.png) !important;
}
';
}
add_action('login_head', 'custom_login_logo');

function admin_logo_url() {
    return home_url();
}
add_filter('login_headerurl', 'admin_logo_url');

function admin_login_title()  {
    return 'Park Systems';
}
add_filter('login_headertitle', 'admin_login_title');
// ends

// remove wordpress custom user role
remove_role( 'subscriber' );
remove_role( 'editor' );
remove_role( 'contributor' );
remove_role( 'author' );
// ends

Hope you will find those tips helpful, thanks and please feel free to share your thoughts.