• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

Wordpress Different User, Different CSS How ???

Meenakshi Sandle

Active member
Banned User
Apr 9, 2020
162
38
28
30
Chandigarh
www.trendingmantra.com
Hi,

I added some custom css (wordpress font increase or color change) in WordPress backend, I want that CSS only apply on the particular user, not to all WordPress users?

How can this possible? Please Help me.

Meenakshi
 
wrap the css code or style sheet inside php echo. trigger php code based on wordpress user role

global $current_user;
get_currentuserinfo();
if ( user_can( $current_user, "author" ) ){
// do something with echo
}

I never tried it. if this didn't work, I don't see any work around.
 
wrap the css code or style sheet inside php echo. trigger php code based on wordpress user role

global $current_user;
get_currentuserinfo();
if ( user_can( $current_user, "author" ) ){
// do something with echo
}

I never tried it. if this didn't work, I don't see any work around.
Thnx but where to paste this code.. I m not such tech person. Plz explain it more abit plz.
 
Thnx but where to paste this code.. I m not such tech person. Plz explain it more abit plz.
Then i want to know below details
1. from where you are adding custom css - page builder or directly from theme?
2. what theme or page builder you are using.
3. exactly what css code you are trying to insert and what content it is going to affect.

only after knowing these details I can think and let you know solution in detail.
 
Thnx but where to paste this code.. I m not such tech person. Plz explain it more abit plz.
1. You can use below plugin to create shortcode for your php code
2. download and add below library for generating dynamic php css

3. create your php css code as per examples given in github link from step 2

4. place your created code in php code section of the plugin installed in step 1 and generate short code

5. place your short code in the pages where ever you want the dynamic css needs to reflect.

6. don't forget to wrap code created in step 3 using below code
global $current_user;
get_currentuserinfo();
if ( user_can( $current_user, "author" ) ){
// dynamic php css goes here
}
 
1. You can use below plugin to create shortcode for your php code
2. download and add below library for generating dynamic php css

3. create your php css code as per examples given in github link from step 2

4. place your created code in php code section of the plugin installed in step 1 and generate short code

5. place your short code in the pages where ever you want the dynamic css needs to reflect.

6. don't forget to wrap code created in step 3 using below code
global $current_user;
get_currentuserinfo();
if ( user_can( $current_user, "author" ) ){
// dynamic php css goes here
}
Thank you for your reply... I mean..

there are 3 users, i need to make css for all the users EXCEPT 1.. how can i code this ?? Thank you
 
You have to be a little more specific. Like: what's the difference between those 3 users? 1 is admin and others are subscribers? All are subscribers? The 1 different is about user type or username?

What you're asking is like: I have 3 identical cars. The one I drive I want to be different. But I won't tell you which one I drive.
 
You have to be a little more specific. Like: what's the difference between those 3 users? 1 is admin and others are subscribers? All are subscribers? The 1 different is about user type or username?

What you're asking is like: I have 3 identical cars. The one I drive I want to be different. But I won't tell you which one I drive.
" Its just a simple dynamic website, not much complex....

- There are 3 admin accounts, My Account (1) & other 2 admin accounts also...
- So total 3 ADMIN accounts....

- I had already hidden some content in wordpress Backend panel via Manual CSS.
- Now I need to see all content for myself.

- But I need to Hide that backend stuff for OTHER ADMIN USERS." I want the to say, I want to see all my backend content whereas to other admin users it should be hidden.

I really hope you got my point, what I m trying here to say.

Thank you
 
PHP:
function hide_for_others() {
$current_user = wp_get_current_user();
if (!$current_user->user_login == 'your username') { ?>
<style type="text/css">
#whatever_css_id_you_want_to_hide {
your style here
}
.whatever_css_class_you_want_to_hide {
    your style here
}
</style>
<?php }
}
add_action( 'admin_init', 'hide_for_others');

Modify as you need it and place this code in your functions.php or in child theme's function.php

Edit: do not forget to clear/purge cache if you're using caching plugins and first test it on incognito window if you don't want to clear cache and cookies of your usual browser.
 
Last edited:
PHP:
function hide_for_others() {
$current_user = wp_get_current_user();
if (!$current_user->user_login == 'your username') { ?>
<style type="text/css">
#whatever_css_id_you_want_to_hide {
your style here
}
.whatever_css_class_you_want_to_hide {
    your style here
}
</style>
<?php }
}
add_action( 'admin_init', 'hide_for_others');

Modify as you need it and place this code in your functions.php or in child theme's function.php

Edit: do not forget to clear/purge cache if you're using caching plugins and first test it on incognito window if you don't want to clear cache and cookies of your usual browser.




Why this showing here ??

Error.png
 
place this code in your functions.php

What did I say?

Anyway small change to the code:

PHP:
function hide_for_others() {
$current_user = wp_get_current_user();
if ($current_user->user_login != 'your username') { ?>
<style type="text/css">
#whatever_css_id_you_want_to_hide {
your style here
}
.whatever_css_class_you_want_to_hide {
    your style here
}
</style>
<?php }
}
add_action( 'admin_init', 'hide_for_others');

Please notice that logic of if changed as you need for others not for you.
 
  • Like
Reactions: tradesman
What did I say?

Anyway small change to the code:

PHP:
function hide_for_others() {
$current_user = wp_get_current_user();
if ($current_user->user_login != 'your username') { ?>
<style type="text/css">
#whatever_css_id_you_want_to_hide {
your style here
}
.whatever_css_class_you_want_to_hide {
    your style here
}
</style>
<?php }
}
add_action( 'admin_init', 'hide_for_others');

Please notice that logic of if changed as you need for others not for you.

If I place this code in (functions.php) then it will be deleted after theme updates... how to solve this problem ?? I just need not to show this code to anyone..
 
Make a child theme of your theme and place this code in your child theme functions.php.

Why you should use Wordpress Child Themes?
Since a child theme inherits the characteristics of a master or a parent theme, you can customize its code without breaking the original’s functionality. This way, if a theme gets an update, all of the changes you made won’t be overwritten.

How to create a Wordpress child theme?
Please google yourself.
 
Make a child theme of your theme and place this code in your child theme functions.php.

Why you should use Wordpress Child Themes?


How to create a Wordpress child theme?
I know CHILD THEME !!! But the thing is there are just few code in child theme. Anyone can find this manual code... hmmm.. I need no one can see this code. I place this code under bundle of coding.. HUGGGGE Code.
 
@Meenakshi Sandle my approach for this is refer to user id that is unique not admin role. WP has core function for this : wp_get_current_user()->ID == 1 (e.g. you want to catch user that has id of 1)
Let say you are user 1, to hide something in backend to others you have to declare
wp_get_current_user()->ID != 1 and use WP hook as 'admin_menu' :

Code:
 function remove_menus(){

if ( wp_get_current_user()->ID != 1 ) {
remove_menu_page( 'index.php' );
remove_menu_page( 'tools.php' );
remove_menu_page( 'edit-comments.php' );
remove_menu_page( 'edit.php?post_type=page' );
remove_menu_page( 'wpcf7' );
remove_menu_page( 'woocommerce' );
remove_menu_page('edit.php');
remove_menu_page( 'plugins.php' );
remove_menu_page( 'themes.php' );
remove_menu_page( 'options-general.php' );
remove_menu_page( 'vc-welcome' );
remove_menu_page( 'porfolio.php' );
}
}

add_action( 'admin_menu', 'remove_menus' );

To hide something in admin bar use WP hook 'admin_bar_menu':

Code:
// If not Administrator partila hide toolbar

  add_action( 'admin_bar_menu', 'remove_wp_logo', 999 );
  function remove_wp_logo( $wp_admin_bar ) {

      if ( wp_get_current_user()->ID != 1 ) {
     $wp_admin_bar->remove_node( 'wp-logo','edit');
     // $wp_admin_bar->remove_node( 'edit');
     $wp_admin_bar->remove_node( '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-page' );
     $wp_admin_bar->remove_node( 'new-shop_order' );
    $wp_admin_bar->remove_node( 'new-shop_coupon' );

     }
}
Hope it helps.
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock