The most simple way to hide a field programmatically is to use the native acf/prepare_field
hook. As explained in the ACF documentation, it is possible to hide a field by returning false
. Here is a usage example:
add_filter('acf/prepare_field/name=my_field', 'my_prepare_field');
function my_prepare_field($field){
// hide in backend
if(is_admin()){
return false;
}
// return normally
return $field;
}
When registering field groups with add_local_field_group()
, we can directly set a callback on the acf/prepare_field
using the Inline Hooks (See documentation). Here is usage example:
$field = array(
'label' => 'My Text',
'key' => 'field_my_text',
'name' => 'my_text',
'type' => 'text',
'callback' => array(
'prepare_field' => function($field){
// hide in backend
if(is_admin()){
return false;
}
// return normally
return $field;
}
)
);
We can also hide a field from the admin directly from the Field Group UI, using the Advanced Settings. Usage example:
A more simple solution is to use the Field Visibility Widget, which allow to hide a field directly from the Field Settings, using a dropdown.