# How to remove these fields from the 'Profile' section?

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
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

<?php
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();
</script>
<?php }
}
?>


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

-

For the contact methods filter: user_contactmethods.

add_filter( 'user_contactmethods', 'update_contact_methods',10,1);

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

return $contactmethods; }  - 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. - +1 Awesome! Awesome! (...but I like to hack the core, I call it 'enhancing'.) – EarnestoDev Nov 3 '11 at 15:03 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 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 –  gmaggio May 30 '12 at 7:24

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;
}

}


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 –  Cor van Noorloos 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:

<script type="text/javascript"> jQuery(document).ready(function( $){$("#nickname,#display_name").parent().parent().hide(); }); </script> 

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');

{
{

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.