custom css in admin panel by user id
Question
I'm looking for adding a custom css in the admin panel by targeting user id cause I have another administrator but I want to hide something from him by css. I'm using this code to put some stylesheet files in the admin panel, but its for all users
add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
echo ' <link rel="stylesheet" type="text/css" href="../../admincss.css?v=1.3">';
}
Solution 2
done it
add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
global $current_user;
$user_id = get_current_user_id();
if(is_admin() && $user_id == '2'){
echo ' <link rel="stylesheet" type="text/css" href="../../new.css">';
}
}
OTHER TIPS
Use below code into functions.php file. Make sure you are using it right way use admin_enqueue_scripts
add_action('admin_enqueue_scripts', 'FUNCTION_NAME');function FUNCTION_NAME() {
global $current_user;
$user_id = get_current_user_id();
if(is_admin() && $user_id == '2'){
wp_enqueue_style( 'admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' );
}}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange