Agregar clases de rol al body en WordPress

  1. In your WordPress dashboard, go to Appearance and then select Theme Editor.

  2. On the right side, locate and click on the "functions.php" file.

  3. Insert the following code at the end of the functions.php file: php function add_role_to_body($classes) { if (is_user_logged_in()) { $user = wp_get_current_user(); $user_role = implode(' ', $user->roles); $classes[] = 'role-' . $user_role; } return $classes; } add_filter('body_class', 'add_role_to_body');

  4. Click the "Update File" button to save the changes.

  5. The classes of the user's roles will now be added to the body tag of your WordPress site.