skip to Main Content

So I’m using this plugin called Mapplic for interactive maps on wordpress
and I’m trying to hide a specific class in it for everyone except admins
so first i added this function to add a class for admin

function add_admin_body_class($classes) {
    if (current_user_can('administrator')) {
        $classes[] = 'is-admin';
    }
    return $classes;
}
add_filter('body_class', 'add_admin_body_class');

then i added the CSS code which is

.mapplic-popup-body {
    display: none !important;
}

body.is-admin .mapplic-popup-body {
    display: flex !important;

now it’s completely not showing the class for everyone including the admins
could anyone help me out with this please ?

so i tried changing the class in CSS from is-admin to wp-admin and it showed the class in the admin dashboard but i wanna see it in the content itself

2

Answers


  1. Try simple CSS.

    body:not(.is-admin) .mapplic-popup-body{
     display:none;
    }
    

    This will hide the container only if admin is not logged in.

    Login or Signup to reply.
  2. If you want to hide the class mapplic-popup-body for all users except administrators in WordPress, you can use the following code snippet in your theme’s functions.php file:

    function hide_class_for_non_admins() {
        if (!current_user_can('administrator')) {
            // Output the CSS to hide the specific class
            echo '<style>
                .mapplic-popup-body {
                    display: none !important;
                }
            </style>';
        }
    }
    add_action('wp_head', 'hide_class_for_non_admins');
    

    Feel free to reach out if you have any further questions!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search