• Hi, I’m trying to load CSS on specific user roles following this post but for some reason is not working and I’m wondering why?

    I’m trying to hide a field on the LatePoint plugin but only for the latepoint_agent role.

    I tried as a snippet, on funtions.php but nothing works.

    add_action( 'admin_head', function () {
        
        //Get current user ID, if the user is logged in.
        if ( is_user_logged_in() ) {
            $user_id = get_current_user_id(); }
        
        // Get the user object.
        $user = get_userdata( $user_id );
    
        // Get all the user roles for this user as an array.
        $user_roles = $user->roles;
    
        // Check if the specified role is present in the array.
        if ( in_array( 'latepoint_agent', $user_roles, true ) ) { ?>
    
        <style>
    
          .os-col-12n {display:none; !important}
    
        </style>
        <?php
        }
    } );

    • This topic was modified 1 year, 5 months ago by rijotech.
Viewing 2 replies - 1 through 2 (of 2 total)
  • I tried as a snippet, on funtions.php but nothing works.

    What exactly do you mean by “nothing works”?

    Do you see the CSS printed in the <head>, but it doesn’t do what you expect it to do, or do you not see the CSS printed at all?

    When I swap latepoint_agent for administrator in your code to check for WordPress’ native Administrator role, I can get your code to print the CSS in the <head> when an administrator is logged in.

    But I can’t test beyond this because LatePoint is a commercial plugin and WordPress support volunteers here do not have access to such commercial products to install and help in circumstances like this.

    If you cannot get the CSS to print in the head at all, please confirm you’re using the correct slug for the custom user role this plugin creates.

    If you’re getting the CSS to be printed but it’s not doing what you want it to do, this would be due to using the wrong CSS selector. In this case, kindly use your browser’s developer tools to inspect the elements and change your CSS selector.

    And if none of that helps, please get in touch with the plugin’s developer for help. They built and sold the plugin, and they should be in a better position to help you with this.

    Good luck!

    The CSS declaration in your code seems to be incorrect. You should place the semicolon at the end of the statement. Here’s the corrected version:

    .os-col-12n { display: none !important; }

    This will properly apply the “display: none” style with the “important” priority to the elements with the class “os-col-12n“.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘User roles custom css not working’ is closed to new replies.