Support

Account

Home Forums General Issues Give body a class based on true/false checkbox Reply To: Give body a class based on true/false checkbox

  • For me, I had a dropdown selection for some page options and needed to add a body class for each selection for styling.

    add_filter('body_class', 'add_acf_body_class');
    function add_acf_body_class($class) {
        $field = get_field_object('page_width', get_queried_object_id());
        $value = $field['value'];
        $label = str_replace( '_', '-', $value ); //Change _ to -
        $class[] = $label;
    
        return $class;
    }