Blog

2017.11.09

How to remove WordPress admin Profile page fields (Including Personal Options, Biographical Info, Website etc.) and titles without JS

Recently had been working on this project of mine where I came upon a problem – how to remove WordPress admin Profile page fields and titles that will not be needed for users who will be using the new system.

You do not want your users to be confused with information that they don’t have to input therefore it might be a good idea to remove them. And I mean removing them since hiding is not an option and it involves CSS or JS solution that makes those fields and titles disappear after the page has loaded and it means that the user gets to see some flickering in the fields.

Here is the final result of my Profile page:

WordPress admin profile page without personal input fields

In my case I needed the following fields and titles to be removed from the WordPress admin Profile page:

  • “Personal Options” title
  • “Visual Editor” checkbox (Disable the visual editor when writing)
  • “Keyboard Shortcuts” checkbox (Enable keyboard shortcuts for comment moderation)
  • “Name” title
  • “Toolbar” checkbox (Show Toolbar when viewing site)
  • “Nickname” field (which is required therefore it still has to be hidden not removed)
  • “Display name publicly as” dropdown
  • “Contact Info” title
  • “Website” field
  • “About Yourself” title
  • “Biographical Info” textarea field
  • “Profile Picture” image

I searched the internet all over and wanted to find a solution that would be based on WordPress hooks and wold allow me to unset or alter the output of the Profile page but with no luck. In the end I came across a solution that hooks into the output of the admin Profile page and allows you to use preg_replace function in order to cut out information that is not needed.

Since the structure of the page is laid out in tables and rows, I had to base the preg_replace function on table row classes and heading content had to be used in order to find them and replace them with nothing. Yes, this is not a beautiful solution and it will work until WordPress doesn’t change the classes or structure of the Profile page but that usually doesn’t happen so often.

So here is the solution How to remove WordPress admin Profile page fields (Including Personal Options, Biographical Info, Website etc.) and titles without JS. Simply copy and paste it in your functions.php file:

// Remove fields from Admin profile page
if ( ! function_exists( 'cor_remove_personal_options' ) ) {
	function cor_remove_personal_options( $subject ) {
		$subject = preg_replace('#<h2>'.__("Personal Options").'</h2>#s', '', $subject, 1); // Remove the "Personal Options" title
		$subject = preg_replace('#<tr class="user-rich-editing-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Visual Editor" field
		$subject = preg_replace('#<tr class="user-comment-shortcuts-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Keyboard Shortcuts" field
		$subject = preg_replace('#<tr class="show-admin-bar(.*?)</tr>#s', '', $subject, 1); // Remove the "Toolbar" field
		$subject = preg_replace('#<h2>'.__("Name").'</h2>#s', '', $subject, 1); // Remove the "Name" title
		$subject = preg_replace('#<tr class="user-display-name-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Display name publicly as" field
		$subject = preg_replace('#<h2>'.__("Contact Info").'</h2>#s', '', $subject, 1); // Remove the "Contact Info" title
		$subject = preg_replace('#<tr class="user-url-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Website" field
		$subject = preg_replace('#<h2>'.__("About Yourself").'</h2>#s', '', $subject, 1); // Remove the "About Yourself" title
		$subject = preg_replace('#<tr class="user-description-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Biographical Info" field
		$subject = preg_replace('#<tr class="user-profile-picture(.*?)</tr>#s', '', $subject, 1); // Remove the "Profile Picture" field
		return $subject;
	}

	function cor_profile_subject_start() {
		if ( ! current_user_can('manage_options') ) {
			ob_start( 'cor_remove_personal_options' );
		}
	}

	function cor_profile_subject_end() {
		if ( ! current_user_can('manage_options') ) {
			ob_end_flush();
		}
	}
}
add_action( 'admin_head', 'cor_profile_subject_start' );
add_action( 'admin_footer', 'cor_profile_subject_end' );

So this does the trick and removes fields from admin Profile page but we are not able to remove the nickname field like this since it is mandatory. So for this I am still using the solution with JS like so:

//Remove fields from Admin profile page via JS to hide nickname field which is mandatory
function remove_personal_options(){
	if ( ! current_user_can('manage_options') ) { // 'update_core' may be more appropriate
		echo '<script type="text/javascript">jQuery(document).ready(function($) {
			$(\'form#your-profile tr.user-nickname-wrap\').hide(); // Hide the "nickname" field
		});</script>';
	}
}
add_action('admin_head','remove_personal_options');

And the only thing that could be removed via hook was Admin color scheme and it is done like so:

// Removes ability to change Theme color for the users
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );

Let’s hope that WordPress team will soon create hooks that will easily allow us to change the admin Profile page but for now this is what worked for me beautifully. No need to hide the fields using Javascript, just use the above code and throw out the lines you do not wan’t to be removed.

In categories: Tutorials, Website development, Wordpress

Nauris Kolāts

Nauris is a freelance designer / developer who loves to dig into the UX as much as in the ground for fishing worms. And fishing is just one amongst the long list of his active lifestyle hobbies.

Other posts

Your thoughts

Join the discussion

  1. erick

    I tried your code, but proof reading, english options, language, ignored phrases are still there. I want to hide them also, please help.

    Screenshot is here – https://imgur.com/QzSceaa

    • Hi Eric,

      It looks like you are using some sort of custom plugins or themes, is that right?
      This tutorial only covers default WordPress Profile panel and does not far beyond that. In order to remove plugin specific fields from admin profile page you will have to dig into the code of the plugin that is creating these additional fields.

  2. erick

    Thanks for your reply and suggestion, after an hour of working it out. I found out that my jetpack plugin’s proofreading feature is the problem.

  3. Torben Wiesbach

    I tried your snippets, but the only part that worked is “Removes ability to change Theme color for the users”. The other additional code doesn’t affect my profile page in any way. Have you got any idea why?

    • Hey Torben,

      Hmm, it is quite hard to tell what could be the issue there, but it should be related to functions.php file.
      I just checked the code and tested it on the latest WP version and it still works as it should.

      I would suggest you to also take a look at other plugins you have setup and try to disable them and test again. Or even download a blank theme and test it there.

      Best

  4. Lalit

    Nauris, you are a genius. I was looking for this solution and I found it on your site. Thanks

  5. Colleen

    Thank you so much for this helpful post!
    @Torben Wiesbach, I know I’m late to reply, but I realized that I could still see everything because I was logged in as an admin. When I logged in as a lower permission user, it was all removed. Hope that helps you!

  6. nadja petrov

    Hello, thanks for this post, is excelent! now on the profile page, users can swap from any roles, it is posible to remove the USER ROLE too on users profile page? thanks…

    • Hi Nadja,

      Thanks for your comment.
      I just did a couple of tests and wasn’t really able to reconstruct your scenario.
      The only time I’m able to change a role for the user is when I’m trying to create a new user and there I’m able to select which role should he be assigned to.
      If your users really can switch between different roles then it sounds more like some sort of a plugin that you have setup there. Try disabling your plugins to find out which one adds this functionality and then work your way up to solve this issue.
      By default WordPRess doesn’t allow your registered users to change their role from e.g. “Customer” to “Administrator” since that would be a major security concern.

      Best wishes

  7. AM

    Thank you Thank You! It worked perfectly.

  8. Frank J.

    This is a really good method, Nauskas. Thanks for sharing it!

    I was looking for something like this for quite a while already. I could set it up easily even though I have only very limited PHP knowledge.

    Thanks, Frank

    PS. The email field in this form shows an error when I enter my real email.

    • Hi Frank, thnaks for your feedback.
      Glad the tutorial helped you and we will take a look at the form.

  9. Amine Laissoub

    Hey Nauris,

    Great article and same like you I was so annoyed to see so many unnecessary fields hanging around and make the CMS looks so cluttered.

    However, you actually can just use custom CSS to achieve the same thing and no need to edit your theme.

    I have to confess it is a very tedious job but better practice. I had to use a lot of these:

    label[for=”page_for_posts”], input[name=”posts_per_rss”], select[name=”start_of_week”] {display: none}

    • Hey Amine, yes, it is true, changing this with CSS can seem quite easy, but that may not be the most secure way since you are only hiding these values from the screen. If a user is more experienced one, he might alter the CSS, reveal these fields and submit them. It may not necessarily mean that it could create any harm, but still, it’s not the method I would suggest to be sure that these fields are not being saved.
      Also I have noticed that WordPress updates time after time their CSS classes and it may require you to keep track on each new version release to make sure the fields are still hidden. With the approach outlined in the article, it should be more stable since changing the core field names happens on a rare occasions.
      But thank you for your suggestion, it is a viable solution that can be really used to hide these fields and make the page cleaner :)

  10. Jhones

    Hello ! Thank you very much for this solution.
    I just wanted to add in response to Torben Wiesbach’s comment, I had the same issue, but it turned out that the other additional code works if you are not logged in as an admin.
    Best of luck to all

  11. Truni

    Thanks!
    Tested with WordPress (2021 octuber):
    With the Admininistrator role only the hook runs ok!
    But we have another role with “edit user” capabilities, and with this role the code works ok!
    Dont know why…
    PD: I do not recommend hiding the “show publicly as” field. Because when you create the user, it is generated automatically, but if you want to edit the lastname later, the public name will not be changed.

  12. same as before

    Also add:

    $subject = preg_replace(‘#’.__(“About the user”).’#s’, ”, $subject, 1); // Remove the “About the user” title

Latest work