Home › Forums › General Issues › Hiding a field on the admin screen
I have a field that I would like to hide on the admin screen of a post. Is there a filter I can modify to hide a specific field?
There is nothing built into ACF that will let you hide a field. You will need to add custom CSS to the admin head https://www.advancedcustomfields.com/resources/acf_head-input/
Thanks for the quick reply. Instead of simply hiding it, I’d like to not load it at all. It’s a resource intensive field with hundreds of values stored in it, and it takes a considerable amount of time to load so that’s the reason I was wondering if there was an existing filter that I could use…
do you want to remove this field for everyone, or just certain types of users?
Everyone would be ideal. (the field is updated on the frontend by customers)
Well, if you’re using ACF pro, there is a hook you can use to remove the field on the back end, but it’s not something that’s documented. I have a plugin that lets you set removal of field by user type. You could use the hook I’m using to remove specific field if is_admin() returns true.
You may need to play with this a bit to get it to work, the ACF hook is acf/get_fields
, like I said, it’s not documented.
You can find it called on line 740 of /api/api-field.php. You need to set the priority > 10 to run after the internal ACF filter.
add_filter('acf/get_fields', 'your_function_name', 20, 2);
function your_function_name($fields, $parent) {
// remove the fields you don't want
return $fields;
}
It’s just a starting point. $fields can be a nested array of fields => sub_fields.
If you want you can see how I do this for user types on line 89 of this file https://github.com/Hube2/acf-user-role-field-setting/blob/master/acf-user-role-field-setting.php
Magic. I am using ACF Pro. This is exactly the direction I needed. Thank you so much.
ACF is absolutely amazing.
Another solution could be to define a conditional logic.
if field1 “value is equal to” true && field1 “value is equal to” false
In ACF Pro v5.9 or more, you can do :
function your_function_name($field) {
return false;
}
add_filter("acf/prepare_field/name=my_acf_field", "your_function_name");
solution by @olivier-guilleux is now correct. My comment from 5 years ago was before the prepare_field hook was added to ACF.
i have used this intuitively and it has worked from day 1 not knowing really how or why.
if you add class hidden
to the field, it won’t appear on the admin view / backend but it is still usable.
we use that all the time.
Thanks in my case i us it for token field in a repeater.
The field is show only the fisrt time
function hide_token_field($field) {
if($field[‘value’]){
return false;
}else{
return $field;
}
}
add_filter(“acf/prepare_field/name=token”, “hide_token_field”);
The topic ‘Hiding a field on the admin screen’ is closed to new replies.
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.