How do I display a custom field for a specific role, but not display it on the profile page of the admin? When admin goes to edit a profile user that this role, the field will visible.

I created two fields for Subscriber role, but the fields appears on admin profile page. I need to display these fields only if admin goes to the profile page of subscribers.

function show_custom_field_for_subscriber(){

    if( current_user_can('administrator') || current_user_can('subscriber') ) {

    //code html for display the fields


add_action( 'show_user_profile', 'show_custom_field_for_subscriber' );

1 Answer 1


You can use the WP_User class and the has_cap($role) method. The show_user_profile action passes a WP_User object as a parameter to the called function.


add_action('show_user_profile', 'my_add_extra_profile_fields');
function my_add_extra_profile_fields($user) {
    if ($user->has_cap('subscriber'))
        //Code here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.