NO BUG: Dynamic Body Class not working if using dynamic data

I’m trying to add a dynamic class to the body tag here:
image

using an ACF field that’s set up like so:

If I manually enter a value, the class is output fine, if I use an acf field, no class is added. Am I missing something to make this work? I tried on cpt templates as well as single pages, same results.

I’m not sure if my option will help or if it’s right, but maybe you forgot to query the loop?

Hey Martin,

thanks for your report.

I think you have to explain your setup a bit more in detail as it works as expected for me (see quick screencast).

Best,

André

Thanks a lot for the screencast, I found the culprit. Turns out it doesn’t work with option pages. If I set the field group to only show on pages and/or posts, but not on option pages, it works as expected. Could’ve thought of testing that way myself first haha, brain was fried I guess.

I’ll try n go into more details of how it doesn’t work with options pages but I’d be happy to dm or mail you some logins.

  1. I have a regular Archive Template for a CPT
    archive

  2. I add an options page to it like so:

if( function_exists('acf_add_options_page') ) {
    acf_add_options_page(array(
        'page_title'    => 'Gym Archive Settings',
        'menu_title'    => 'Gym Archive Settings',
        'menu_slug'     => 'gym-archive-settings',
		'parent_slug'   => 'edit.php?post_type=gym',
        'capability'    => 'edit_posts',
        'redirect'      => false,
		'icon_url' 		=> 'dashicons-admin-site',
        'position' 		=> 3
    ));
}
  1. On that options page I have an image field, a title field and a text field. Pulling all those inside the template works as expected.

  2. When I now add the new field for the class (regular text field) and output that anywhere inside the template, it also works as expected.

  3. If I however, put that field into the Body Class field, it doesn’t work.

My assumption, no clue how right or wrong it might be, is that the Body Class field doesn’t expect/check for fields coming from option pages. Or even if it does, it doesn’t add the ‘option’ attribute to the get_field('field_name', 'option') function from ACF. It seems to only work when the value is being pulled from a single page/post.

Hey Martin,

I can’t confirm that. Works for me with an options page as well.

If you use the same field group for posts / pages and option pages Bricks probably won’t know which one to pull.

Not sure what your exact scenario is. Maybe you create a small helper function to fetch and return the body classes like you want and then use this function in the page settings: {echo:my_body_classes_function}.

Best,

André

Hmm damn it, thought I found the rootcause haha. I did try with a separate group but same result. Anyways, helper function is a good workaround and I’ll keep investigating what I did to mess up the functionality. Thanks for the help :slight_smile: