I am using Wordpress with Full Site Editing enabled.
Wordpress =< 6.1
Now I am customizing a theme that uses theme styles in the FSE - so the user can select their desired preset styles.
Since our themes shall be based on one FSE theme, but with different styles I was hoping to find out which .json
is currently selected, and change the enqueued JS & CSS files accordingly to have extra styling control.
I am wondering if it is possible to find out what style is currently active through PHP?
I was not able to find anything that helped me in the documentation so far.
Given your scenario, I recommend having your base FSE theme as the Parent theme then creating Child themes for all your variations, this ensures the correct JS and CSS is loaded per child theme and also maintains versioning.
However, there is the WP_Theme_JSON_Resolver - which states "This class is for internal core usage and is not supposed to be used by extenders", so with that in mind, you can find the information you are looking for like get_style_variations()
and get_user_data_from_wp_global_styles()
which returns the original style configuration. I wouldn't recommend relying on this class..
Depending on what change/variation you are looking for in your style, wp_get_global_stylesheet() returns WP_Theme_JSON which contains all the style information from merging core, theme, and user data.