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';
}
break;
default:
break;
}
}
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.
<style>
.hideme {
display: none;
}
</style>
Hope this helps.
Jeff
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.