Title: Custom Code for Hiding Profile Fields
Last modified: July 29, 2021

---

# Custom Code for Hiding Profile Fields

 *  Resolved [tech techno](https://wordpress.org/support/users/asifshaikhtsn/)
 * (@asifshaikhtsn)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/custom-code-for-hiding-profile-fields/)
 * i m using these code to hide extra field from profile page but these code will
   apply this setting for All Roles but i need to exclude admin and superadmin from
   this code.
 * can someplease please customize this code so that these extra field will hide
   only for other roles user not for admin
 *     ```
       function remove_extra_field_profile()
       {
   
           $current_file_url =  preg_replace( "#\?.*#" , "" , basename( $_SERVER['REQUEST_URI'] ) );
   
           if( $current_file_url == "profile.php" )
           {
               add_action( 'wp_loaded', function(){ ob_start("profile_callback"); } );
               add_action( 'shutdown', function(){ ob_end_flush(); } );
           }
       }
       add_action( 'init', 'remove_extra_field_profile' );
   
       function profile_callback( $html )
       {
           $profile_dom = new DOMDocument;
           $profile_dom->loadHTML( $html );
   
           $all_lines = $profile_dom->getElementsByTagname( 'tr' );
   
           $excludes = array(
               'user-rich-editing-wrap',
               'user-admin-color-wrap',
               'user-comment-shortcuts-wrap',
               'show-admin-bar user-admin-bar-front-wrap',
               'user-url-wrap',
       		'user-behance-wrap',
       		'user-nickname-wrap',
       		'user-display-name-wrap',
               'user-description-wrap'
               );
   
           $deletes = array();
   
           foreach ( $all_lines as $line ) 
           {
               $tr_calss = $line->getAttribute("class");
   
               if( in_array( $tr_calss, $excludes ) )
               {
                   $deletes[] = $line;
               }
           }
   
           $deletes[] = $profile_dom->getElementsByTagname( 'h2' )->item(0);
   
           foreach ($deletes as $delete) 
           {
               $delete->parentNode->removeChild( $delete );
           }
   
           return $profile_dom->saveHTML();
       }
       ```
   

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Oderinde Oluwasegun](https://wordpress.org/support/users/webcreative/)
 * (@webcreative)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/custom-code-for-hiding-profile-fields/#post-14716548)
 * You seem to be checking the current URL to see if it’s the profile page. At that
   point, you may want to check check if the user is a (super) admin or not…
 *     ```
       if( ($current_file_url == "profile.php") && !current_user_can( 'manage_options' ) )
           {
               add_action( 'wp_loaded', function(){ ob_start("profile_callback"); } );
               add_action( 'shutdown', function(){ ob_end_flush(); } );
           }
       }
       ```
   
 * See if that works?
 *  Thread Starter [tech techno](https://wordpress.org/support/users/asifshaikhtsn/)
 * (@asifshaikhtsn)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/custom-code-for-hiding-profile-fields/#post-14722685)
 * Thank you [@webcreative](https://wordpress.org/support/users/webcreative/) it’s
   Worked
 *  Thread Starter [tech techno](https://wordpress.org/support/users/asifshaikhtsn/)
 * (@asifshaikhtsn)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/custom-code-for-hiding-profile-fields/#post-14722788)
 * Hey [@webcreative](https://wordpress.org/support/users/webcreative/) Please Help
   me in this case also.i have these two moew code
 * This one is for hiding some option in classic editor
 *     ```
       add_filter("mce_buttons", "tinymce_editor_buttons", 99); //targets the first line
       add_filter("mce_buttons_2", "tinymce_editor_buttons_second_row", 99); //targets the second line
   
       function tinymce_editor_buttons($buttons) {
       return array(
           "undo", 
           "redo", 
           "separator",
           "bold", 
           "italic", 
           "underline", 
           "strikethrough", 
           //"separator",
           //"bullist", 
           //"separator",
           //add more here...
           );
       }
   
       function tinymce_editor_buttons_second_row($buttons) {
          //return an empty array to remove this line
           return array();
       }
   
        function my_editor_settings($settings) {
           $settings['quicktags'] = false;
           return $settings;
           }
   
           add_filter('wp_editor_settings', 'my_editor_settings');
       ```
   
 * and this one is for hiding post slug option while writing post
 *     ```
       function hide_all_slugs() {
       global $post;
       $hide_slugs = "<style type=\"text/css\"> #slugdiv, #edit-slug-box { display: none; }</style>";
       print($hide_slugs);
       }
   
       add_action( 'admin_head', 'hide_all_slugs'  );
       ```
   
 * i use these line to exclude admin from these code but it’s not worked for me
   `
   if ( !current_user_can( 'manage_options' ) )`
 * All these 2 code is working fine but these code is applying for all roles and
   i want to exclude admin role for these code..
 * please tell me how to add any custom code with exclude admin role
 *  [Oderinde Oluwasegun](https://wordpress.org/support/users/webcreative/)
 * (@webcreative)
 * [4 years, 10 months ago](https://wordpress.org/support/topic/custom-code-for-hiding-profile-fields/#post-14728812)
 * > i use these line to exclude admin from these code but it’s not worked for me
   > `
   > if ( !current_user_can( 'manage_options' ) )`
 * Let me see how you are using this?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Custom Code for Hiding Profile Fields’ is closed to new replies.

## Tags

 * [Coding](https://wordpress.org/support/topic-tag/coding/)
 * [Wordpress Developer](https://wordpress.org/support/topic-tag/wordpress-developer/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [Oderinde Oluwasegun](https://wordpress.org/support/users/webcreative/)
 * Last activity: [4 years, 10 months ago](https://wordpress.org/support/topic/custom-code-for-hiding-profile-fields/#post-14728812)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
