Title: Test user role
Last modified: September 13, 2018

---

# Test user role

 *  Resolved [tcumpston](https://wordpress.org/support/users/tcumpston/)
 * (@tcumpston)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/test-user-role-2/)
 * I want to display different images based on the user’s role. I’m trying to use
   if( get_role(‘subscriber’) but to no avail. Can you point me in the right direction?

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

 *  Thread Starter [tcumpston](https://wordpress.org/support/users/tcumpston/)
 * (@tcumpston)
 * [7 years, 8 months ago](https://wordpress.org/support/topic/test-user-role-2/#post-10686291)
 * I changed to current_user_can(“role-a”) and it sort of works. I have 3 rows with
   3 different images.
 * The first row has !is_user_logged_in() and that image shows when the user is 
   not logged in. WORKS PERFECT.
 * The second row has current_user_can(“role-a”) and that image shows when the user’s
   role is role-a. WORKS PERFECT.
 * The second row has current_user_can(“role-b”) and that image shows when the user’s
   role is role-b. CURRENTLY SHOWS THE IMAGE FOR A AND B.
 *  Plugin Author [Jonathan Horowitz](https://wordpress.org/support/users/jhorowitz/)
 * (@jhorowitz)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/test-user-role-2/#post-10736287)
 * Checking roles in this way is deprecated in WordPress. Try using a capability
   instead of a role name in `current_user_can()`.
 * If you must use roles, define this function in your theme’s functions.php:
 *     ```
       function current_user_has_role( $role ) {
       	$user = wp_get_current_user();
       	return $user->exists() && in_array( $role, $user->roles );
       }
       ```
   
 * Then use that function instead of `current_user_can()`.

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

The topic ‘Test user role’ is closed to new replies.

 * ![](https://ps.w.org/content-visibility-for-divi-builder/assets/icon-256x256.
   png?rev=1359961)
 * [Content Visibility for Divi Builder](https://wordpress.org/plugins/content-visibility-for-divi-builder/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/content-visibility-for-divi-builder/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/content-visibility-for-divi-builder/)
 * [Active Topics](https://wordpress.org/support/plugin/content-visibility-for-divi-builder/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/content-visibility-for-divi-builder/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/content-visibility-for-divi-builder/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Jonathan Horowitz](https://wordpress.org/support/users/jhorowitz/)
 * Last activity: [7 years, 7 months ago](https://wordpress.org/support/topic/test-user-role-2/#post-10736287)
 * Status: resolved