2

I want to remove the Display name publicly as option from non-admins in WordPress edit profile page. How is that possible?

enter image description here

if ( ! current_user_can('manage_options') ) {
#remove the above
}

In addition, how is it possible to remove the functionality from subscribers from editing their profile?

1 Answer 1

2

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

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:

    <?php
    // Remove fields from Admin profile page
    if ( ! function_exists( 'cor_remove_personal_options' ) ) {
        function cor_remove_personal_options( $subject ) {

            $subject = preg_replace('#<tr class="user-display-name-wrap(.*?)</tr>#s', '', $subject, 1); // Remove the "Display name publicly as" 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 if you do not want to remove the nickname field like this since it is mandatory. So for this you can use the solution with JS like so:

    <?php 

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

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.

Thanks!

2
  • I think edit_user_profile would be a better hook for this so it doesn't run on every admin page. Jul 5, 2018 at 14:45
  • How is it possible to remove profile link completely from non-admins or even block that page for subscribers
    – csandreas1
    Jul 19, 2018 at 7:52

Your Answer

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

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