# Body Classes From ACF True/False Fields

> Adds a body class such as "acf-hide-title" when a true/false field is switched on for the current page, so you can change the layout with CSS alone.

- Type: PHP
- Runs: Frontend only
- Category: [Custom Post Types & Fields](https://wpide.com/library/category/post-types/)
- Tags: acf, body-class, css
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/acf-true-false-body-class/

## Code

```php
// True/false field names that become body classes.
$wpide_acf_class_fields = array( 'hide_title', 'full_width', 'transparent_header' );

add_filter( 'body_class', function ( $classes ) use ( $wpide_acf_class_fields ) {
    if ( ! is_singular() || ! function_exists( 'get_field' ) ) {
        return $classes;
    }

    foreach ( $wpide_acf_class_fields as $name ) {
        if ( get_field( $name, get_queried_object_id() ) ) {
            $classes[] = 'acf-' . sanitize_html_class( str_replace( '_', '-', $name ) );
        }
    }

    return $classes;
} );
```

## Notes

List your true/false field names. The class is "acf-" plus the field name with dashes.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Body Classes From ACF True/False Fields" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
