Title: functions.php
Last modified: August 21, 2021

---

# functions.php

 *  Resolved [kklo](https://wordpress.org/support/users/kklo/)
 * (@kklo)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/functions-php-7/)
 * Hi,
 * I have two types of users. User1 and User2
 * I want this CSS line
 * #st-content-wrapper .widgets .widget-box {
    display: none !important; }
 * appear for for user1 and do not appear for user2 and when user2 logs in, the 
   CSS line does not appear.
 * I looked in the documentation for a way to put this CSS line in functions.php,
   I couldn’t find it.
 * Can someone help me?
 * Thanks
    -  This topic was modified 4 years, 9 months ago by [Yui](https://wordpress.org/support/users/fierevere/).
    -  This topic was modified 4 years, 8 months ago by [Jan Dembowski](https://wordpress.org/support/users/jdembowski/).
      Reason: Moved to Fixing WordPress, this is not an Developing with WordPress
      topic

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14789786)
 * You could use the body_class filter
 * see [https://developer.wordpress.org/reference/hooks/body_class/](https://developer.wordpress.org/reference/hooks/body_class/)
 * To add a class based on user1 type or user 2 type
 * then
 *     ```
       body.user1 #st-content-wrapper .widgets .widget-box {
       display: none !important;
       }
       ```
   
 * e.g.
 *     ```
       add_filter( 'body_class', function( $classes ) {
           if ( logic to find if user is user1 type) {
              $classes = array_merge( $classes, array( 'user1' ) );
           }
           return  $classes;
       } );
       ```
   
 *  [corrinarusso](https://wordpress.org/support/users/corrinarusso/)
 * (@corrinarusso)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14789790)
 * This does not sound like a good idea from a scale and customization perspective,
   and at the bare minimum you should really use something Role based, just fyi.
   
   You would get better support if you described what you are trying to acheive.
 * To answer your question use $current_user = wp_get_current_user();
    In a very
   un-elegant way, add this to the header.php file in your child theme:
 *     ```
       <?php 
       	wp_get_current_user();
       	if ( $current_user->user_login =='user1' ) {
       		echo '
       			<style type="text/css">
       			#st-content-wrapper .widgets .widget-box {
       				display: none !important;
       			}
       			</style>	
       		';
       	}
       ?>
       ```
   
 * You may want to investigate this to see if it suits:
    [https://en-ca.wordpress.org/plugins/conditional-widgets/](https://en-ca.wordpress.org/plugins/conditional-widgets/)
 *  [MM Aurangajeb](https://wordpress.org/support/users/aurangajeb/)
 * (@aurangajeb)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14789802)
 * In addition with [@corrinarusso](https://wordpress.org/support/users/corrinarusso/)
   to run custom CSS/Script based on `user_id` ([https://prnt.sc/1qdg6s9](https://prnt.sc/1qdg6s9))
   through the `wp_head` hook. You can use the below example.
 * Example:
 *     ```
       /** Run custom inline CSS based on user ID **/
       add_action( 'wp_head', 'run_my_custom_css');
       function run_my_custom_css() {
       global $current_user;
       $user_id = get_current_user_id();
       if( is_user_logged_in() && $user_id == '30'){
       	?>
       	<style>
       		#st-content-wrapper .widgets .widget-box {
       		display: none !important;
       		}
       	</style>
       	<?php
           }
       }
       ```
   
 * Hook reference- [https://developer.wordpress.org/reference/hooks/wp_head/](https://developer.wordpress.org/reference/hooks/wp_head/)
    -  This reply was modified 4 years, 9 months ago by [MM Aurangajeb](https://wordpress.org/support/users/aurangajeb/).
 *  Thread Starter [kklo](https://wordpress.org/support/users/kklo/)
 * (@kklo)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14789810)
 * Hi, [@corrinarusso](https://wordpress.org/support/users/corrinarusso/), [@alanfuller](https://wordpress.org/support/users/alanfuller/)
 * With this CSS, I want to hide a theme box where it identifies information about
   the Partnership (user), if this user doesn’t pay a monthly fee.
 * But if he pays this monthly fee, this user’s information (box) appears.
 * I found it easier to identify the type of user;
 * user1 – hide box
    user2 – view box
    -  This reply was modified 4 years, 9 months ago by [kklo](https://wordpress.org/support/users/kklo/).
 *  Thread Starter [kklo](https://wordpress.org/support/users/kklo/)
 * (@kklo)
 * [4 years, 9 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14789899)
 * an observation, it’s not one or two users, it’s user roles, like clients
 *  [Alan Fuller](https://wordpress.org/support/users/alanfuller/)
 * (@alanfuller)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14790409)
 * Hiding with CSS is not actually stopping the access. All the use has to do is
   inspect the page and change the CSS with browser tools and they would have access
   to the content they have not paid for.
 * A better strategy is to detect the user type server side and display the widget
   conditionally through server side code.
 * Is the widget something you coded?
 *  Thread Starter [kklo](https://wordpress.org/support/users/kklo/)
 * (@kklo)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14791357)
 * Hi, [@alanfuller](https://wordpress.org/support/users/alanfuller/)
 * I didn’t change the widget.
 * Even though the user group, Customers who didn’t pay to access what was hidden
   with CSS, won’t be able to access the details of the information, it’s more for
   aesthetics.
 * I thought in the form of CSS it would be easier.
 *  [ramonopoly](https://wordpress.org/support/users/ramonopoly/)
 * (@ramonopoly)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14794053)
 * > an observation, it’s not one or two users, it’s user roles, like clients
 * Are you using default [WordPress roles](https://wordpress.org/support/article/roles-and-capabilities/),
   e.g., Author, Editor, Contributor, and so on, or have you created custom roles
   via a plugin?
 * You can check for specific roles in the `roles` property of the user object.
 *     ```
       $user = wp_get_current_user();
       if ( in_array( 'author', (array) $user->roles ) ) {
           // Add your custom CSS for Authors here.
       }
       ```
   
 * > I thought in the form of CSS it would be easier.
 * I agree with the suggestion about [displaying the widget conditionally](https://wordpress.org/support/topic/functions-php-7/#post-14790409).
   If you need to detect roles and add custom CSS accordingly it might not be any
   easier.
 * Or were you imagining to be able to hook into an existing CSS class, for example`
   is-author` or something? If so, I don’t think that’s available by default unfortunately.
 * If you’re comfortable with developing WordPress sites, there are a lot of hooks
   related to sidebars and widgets. For example the [widget_text](https://developer.wordpress.org/reference/hooks/widget_text/)
   hook, which allows you to filter the contents of text widgets.
 * Knowing exactly which widget you want to show and where, would help to narrow
   down the options.
    -  This reply was modified 4 years, 8 months ago by [ramonopoly](https://wordpress.org/support/users/ramonopoly/).
 *  Thread Starter [kklo](https://wordpress.org/support/users/kklo/)
 * (@kklo)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14797026)
 * Hi,
 * In the topic related to tourism, when inserting a tour, there is a field with
   information about the tourism agency, by default. It may or may not be filled.
 * If filled in, this data will appear on the tour page.
 * There are two ways the site makes money:
 * 1 – charging the travel agency commission, in this case the travel agency’s data
   is hidden.
 * 2 – charging a monthly fee from the travel agency, in this case the data is visible
   on the tour page.
 * To differentiate between paying and commissionable travel agencies, I imagined
   using roles and conditioning to be hidden or not with CSS.
 *  Thread Starter [kklo](https://wordpress.org/support/users/kklo/)
 * (@kklo)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14801527)
 * Hi, [@ramonopoly](https://wordpress.org/support/users/ramonopoly/)
 * it worked perfectly, thanks
 *  Thread Starter [kklo](https://wordpress.org/support/users/kklo/)
 * (@kklo)
 * [4 years, 8 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14801638)
 * hi, [@ramonopoly](https://wordpress.org/support/users/ramonopoly/)
 * it worked perfectly, thanks
 * But I need it the other way around. When not the author hides with CSS.
 * Sorry, but I’m just curious about php, could you help me?
 * Thanks

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘functions.php’ is closed to new replies.

## Tags

 * [widgets](https://wordpress.org/support/topic-tag/widgets/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 5 participants
 * Last reply from: [kklo](https://wordpress.org/support/users/kklo/)
 * Last activity: [4 years, 8 months ago](https://wordpress.org/support/topic/functions-php-7/#post-14801638)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
