Home Forums Front-end Issues Hide a specific field frontend Reply To: Hide a specific field frontend

  • Aziz,

    Here is an option for your second question.

    I use the following code to disable a field if a user doesn’t need to see it. You make your logic use any of the WordPress functions to determine when are where to see it.

    add_filter('acf/prepare_field/name=record_number', 'disable_acf_prepare_field');
    function disable_acf_prepare_field( $field ) {
            // Does the user have an Office role?
            $user = wp_get_current_user();
                   if ( in_array( 'office', (array) $user->roles ) ) {
    	              $usergroup = 'office';
    	switch($field['_name']) {	
    		// Which field are we looking for?	
    		case 'record_number':
                       if ($usergroup == 'office' {
    			      // Set the CLASS of the field to use css to hide
    			      $field['wrapper']['class'] = 'hide';
    return $field;

    Then at the top of my php I include the following css style. Can be either added to the page template or some other theme css that is used for the page/post/post-type.

    	.hideme {
    		display: none;

    Hope this helps.