WordPress ACF Readonly

1024px-WordPress_logo.svg

ACF, shorthand for Advanced Custom Fields, is one of the most exclusive plugins there is. It really takes the pain out of custom field creation and makes it really easy to extend your WordPress setup fast. Recenlty I wanted to set some field, which is filled automatically, to read-only to prevent wrong values in this specific field. So I thought ACF covers that. But it turned out this is not possible via the UI (afaik).
Therefore I looked up the documentation and found acf/load_field.

Add the following filter to your functions.php in order to set a field (field_readonly) to readonly:

function acf_set_readonly($field) {
if($field['_name'] == 'field_readonly')
$field['readonly'] = 1;
return $field;
}
add_filter('acf/load_field', 'acf_set_readonly');

Leave a Reply

Your email address will not be published. Required fields are marked *