Sage 10 passing classes/styles to body dynamically

Hi, I need to pass classes or styles to body tag dynamically based on logic created inside a composer, there is a right way to do it?
Thank you

Why do you need to do this?

I need to apply a class to change the background color of the entire page

Composers are tied to individual views (blades) and iirc run after the body classes have already been determined. It’s best to think of Composers are providing data only to the specific view they are associated with, not affecting global state or state “above” their scope (i.e. the body classes). If you want to modify body classes you should filter that somewhere else. If you want to share logic, you should refactor that logic to another location and then call it in the Composer and wherever you filter the body classes.

2 Likes

Hi @sirdoy,

Have you tried to add your body classes logic into body_class filter? This is the best approach to manipulate the body classes in WordPress.

1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.