Support

Account

Home Forums General Issues Adding custom CSS class in body_class() Reply To: Adding custom CSS class in body_class()

  • It could be that ACF does not know where to get the field from. the body tag hook happens outside of the loop.

    
    function add_acf_body_class($class) {
        $queried_object_id = get_queried_object_id();
        $value = get_field('page_layout', $queried_object_id);
        $class[] = $value;
        return $class;
    }
    add_filter('body_class', 'add_acf_body_class');