Skip to content

Instantly share code, notes, and snippets.

@snrjosh
Last active November 27, 2024 21:10
Show Gist options
  • Save snrjosh/46831bdddb6bf09f6cfaa9b9e9ec02e7 to your computer and use it in GitHub Desktop.
Save snrjosh/46831bdddb6bf09f6cfaa9b9e9ec02e7 to your computer and use it in GitHub Desktop.
Hide ACF field on the Admin screen
<?php
/**
* Prevent a field from being rendered
* Filter : https://www.advancedcustomfields.com/resources/acf-prepare_field/
*
*/
function hide_acf_field_on_admin( $field ) {
// Don't show this field if it contains a value.
if ( $field['value'] ) {
return false;
}
return $field;
}
//Specify field name.
add_filter( 'acf/prepare_field/name=field_name', 'hide_acf_field_on_admin' );
/**
* Via CSS
* ACF provides a `acf-hidden` class in acf-global.css,
* which adds a `display: none` to the field in the admin.
* Simply add `acf-hidden` as a class on the field "Wrapper Attributes"
* to hide it on the admin interface.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment