I have to remove some profile fields from the 'Profile' page according to the user roles. For removing the color picker I used remove_action("admin_color_scheme_picker", "admin_color_scheme_picker"). I want to remove these fields:

  1. Nickname
  2. Display name publicly as
  3. AIM, Yahoo, Google talk and About yourself fields
  4. The 'Show Admin Bar' section along with the 2 checkboxes

I went through the file 'user-edit.php' to see if there are any actions/filters that allow me to do so, but it seems there aren't. Can anyone tell me how to do this? Any help would be appreciated. Thanks

EDIT: Thanks @helenhousandi for the answer. I had already did it this way though.

<?php
add_action('admin_footer-profile.php', 'remove_profile_fields');
function remove_profile_fields()
{
    if(current_user_can('custom_role'))
    { ?>
        <script type="text/javascript">
            jQuery("h3:contains('Personal Options')").next('.form-table').remove();
            jQuery("h3:contains('Personal Options')").remove();
            jQuery("h3:contains('About Yourself')").next('.form-table').remove();
            jQuery("h3:contains('About Yourself')").remove();
        </script>
<?php }
}
?>

I know this is a bit longer, but it worked! I think I'll go with @helenhousandi's answer.

  • Where should this go? functions.php? – humpdi Jan 22 '16 at 13:16
  • Yes. It can go to functions.php or a plugin file. As long as the hooks are right, it will work from either of the places. – Rutwick Gangurde Jan 22 '16 at 16:46
  • Ok, but if i put it in the functions.php, how do I return the javascript? with return or echo? – humpdi Jan 25 '16 at 15:31
  • It seems that since WordPress v4.4.1, Nickname has become a required field and gives ERROR: Please Enter A Nickname when updating a user with this hidden but not populated, so you can't just hide it any more – icc97 Apr 6 '16 at 22:08
up vote 13 down vote accepted

For the contact methods filter: user_contactmethods:

function update_contact_methods( $contactmethods ) {

    unset( $contactmethods['aim'] );
    unset( $contactmethods['jabber'] );
    unset( $contactmethods['yim'] );

    return $contactmethods;

}
add_filter( 'user_contactmethods', 'update_contact_methods' );
  • Thanks... got this one! Anything for the 'Show Admin Bar' and 'About yourself' sections? – Rutwick Gangurde Nov 3 '11 at 11:48
  • Please update this if you find a solution... I'm accepting your answer though. Thanks! – Rutwick Gangurde Nov 3 '11 at 14:35
  • +1 because as far as I can recall removing fields via PHP also stops WordPress from creating blank entries in the usermeta table. – Ashfame Apr 9 '12 at 13:12

Though the user_contactmethods filter is the one of the few for the user profile screen, since the other fields are not required in WordPress, you could use jQuery's .hide() and .remove() to effectively get rid of the ones you don't want without complications in terms of saving the information. Sure, a person without JS on would still see them, but that's a small minority and I'm guessing that the information changing there won't actually affect anything.

An example of removing the whole personal options piece (show admin bar and color scheme). I know it's not what you're looking for exactly, just wanted to give you a quick example I have on hand:

// remove personal options block
if( is_admin() ){
    remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
    add_action( 'personal_options', 'prefix_hide_personal_options' );
}

function prefix_hide_personal_options() {
  ?>
    <script type="text/javascript">
        jQuery( document ).ready(function( $ ){
            $( '#your-profile .form-table:first, #your-profile h3:first' ).remove();
        } );
    </script>
  <?php
}

Also, a note about the Show Admin Bar option: in 3.3 the admin bar is becoming the header and thus cannot be turned on or off, so it may not be worth worrying about.

I updated the code example to be more accurate and complete. Had some leftovers in there.

  • Thanks! This is a nice solution! What I did was something similar but I used a different action hook so that my script runs only on profile.php. I also needed to do this for a specific custom role defined in my system. Updating my question with the answer. – Rutwick Gangurde Nov 12 '11 at 11:10
  • 1
    If you add the following to the jQuery it will also hide the Nickname and 'Display Name as' from the question: $("#nickname,#display_name").parent().parent().remove(); – icc97 Feb 1 '12 at 8:16
  • You can also use edit_user_profile hook. And not use the jQuery( document ).ready method to run the code instantaneously. Like this – Giraldi May 30 '12 at 7:24
  • Nickname is required now since WP v.4.4.1 – icc97 Apr 6 '16 at 22:09

From the wordpress support forum you can do the removal using PHP. This removes the About Yourself section:

if (! function_exists('remove_plain_bio') ){
    function remove_plain_bio($buffer) {
        $titles = array('#<h3>About Yourself</h3>#','#<h3>About the user</h3>#');
        $buffer=preg_replace($titles,'<h3>Password</h3>',$buffer,1);
        $biotable='#<h3>Password</h3>.+?<table.+?/tr>#s';
        $buffer=preg_replace($biotable,'<h3>Password</h3> <table class="form-table">',$buffer,1);
        return $buffer;
    }

    function profile_admin_buffer_start() { ob_start("remove_plain_bio"); }

    function profile_admin_buffer_end() { ob_end_flush(); }
}
add_action('admin_head', 'profile_admin_buffer_start');
add_action('admin_footer', 'profile_admin_buffer_end');

The code replaces the 'About Yourself' header with 'Password' and then strips out anything between that and the next table it finds (which is the password table).

Also the plugin WP Hide Dashboard does similar jQuery replacing if you want to extend that.

  • For future reference, you might wish to use admin_head-profile.php and admin_footer-profile.php instead – user5424 Mar 18 '12 at 14:28

BE CAREFUL!!

1) Removing a field may not be good, as on update, if you wont send the essential fields to WORDPRESS update hook, then it might set empty values to those fields! (for example, in submitting form, there should exists i.e. <input name="username".../>)
I Think, that it's better to HIDE from users visually only, with jquery .hide(); and not with .remove();
EXAMPLE code to hide "DISPLAY NAME" and "NICKNAME" fields:

jQuery(document).ready(function( $ ){
    $("#nickname,#display_name").parent().parent().hide();
});

2) To hide admin bar, there is a special option in wordpress menu (in Settings). for custom code, like i.e.

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar()
{
  if (!current_user_can('administrator') && !is_admin()) 
  {
    show_admin_bar(false);
  }
}

As there seems to be no good php hook for this I ended up hiding the fields with CSS then remove them with JS.

add_action( 'admin_head', 'remove_default_profile_fields' );

function remove_default_profile_fields() {

    global $pagenow;

    if( 'profile.php' != $pagenow) return;

    remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );

    // <tr> selectors, each containing a field
    $tr = array(
        "tr.user-rich-editing-wrap",
        "tr.user-comment-shortcuts-wrap",
        "tr.user-first-name-wrap",
        "tr.user-last-name-wrap",
        "tr.user-admin-bar-front-wrap",
        "tr.user-profile-picture",
        "tr.user-user-login-wrap",
        "tr.user-display-name-wrap",
        "h2" // Personally I decided to remove all H2 tags too.
    );

    $selectors = implode(", ", $tr);

    // Hide the fields with css, so even if javascript is disabled they wont show up. 
    echo "<style>{$selectors}{display:none;}</style>"; ?>

    <script type="text/javascript">
        jQuery( document ).ready(function( $ ){
           // Remove selected <tr>'s
           $( '<?= $selectors; ?>' ).remove();
           // Remove any empty table that may have been left over
           $(".form-table:not(:has(tr))").remove();
        });
    </script>

  <?php
}

Use

add_action('admin_head', 'remove_profile_fields');

and add

jQuery(document).ready(function(e) {

before JavaScript.

  • A little explanation would be great! – bravokeyl Sep 22 '16 at 7:13

There's no filter to disable them. Look at the source (/wp-admin/user-edit.php) when you need to do stuff like this. You could hide them with JS but they can still be made visible and values are updated on POST.

Only viable option is to hack the core yourself. Just make sure you handle the update and disregard these fields on POST.

  • Yes, I checked that file already! The JS solution doesn't seem too secure. I'll see what I can do! Thanks! – Rutwick Gangurde Nov 3 '11 at 14:34
  • 3
    If the only solution you can think of is to hack core, then perhaps you shouldn't answer that particular question. You also don't need to suggest to the question asker to look at the file already mentioned, and you are also not correct in stating that there are no filters at all - surely you must have read the question and earlier answer first? – helenhousandi Nov 3 '11 at 14:53
  • @helenhousandi xoxo – EarnestoDev Nov 3 '11 at 14:58

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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