WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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' );
share|improve this question
up vote 4 down vote accepted

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
share|improve this answer
Thanks George Yates, It worked perfect! :) – enoquenroll Aug 7 '13 at 20:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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