Add an option to hide the label for fields in WordPress Advanced Custom Fields

Simply add a hide label option to all fields created with ACF.

<!-- FILENAME: functions.php -->

// Add option to hide label on ACF fields
add_action('acf/render_field_settings', 'hidelabel_render_field_settings');
function hidelabel_render_field_settings( $field ) {  
  acf_render_field_setting( $field, array(
    'label'         => __('Hide Label?'),
    'instructions'  => '',
    'name'          => 'hide_label',
    'type'          => 'true_false',
    'ui'            => 1,
  ), true);  

// (cont.) Add option to hide label on ACF fields
add_filter('acf/prepare_field', 'hidelabel_prepare_field');
function hidelabel_prepare_field( $field )
  if ($field['hide_label'])
    echo '
    <style type="text/css">
      .acf-field-', substr($field['key'],6),' > .acf-label {display: none;}
  return $field;

...Code language: PHP (php)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.