Set global max-width by code for custom theme
-
Hi,
is there a way to set by code the global max-width of generate blocks?
I developing a custom theme and I would like to set this variable reading it from theme.json or a custom option in WP Customizer.
Thank you
-
Do you mean you want to set a max-width for the container block? or all GB blocks? CSS would be an easy option.
Let me know 🙂
I mean to set the global max-width value into GB Settings sections. I wanna keep a universal place where set this value, at the moment I have a custom option in WP Customizer to set it.
Maybe can I set global max-width with some code in functions.php by first retrieving the value from the customiser and then injecting it into generateblock?
Thanks
-
This reply was modified 1 year, 11 months ago by
Stefano.
I actually don’t quite get your idea. The max-width is not an essential attribute for GB blocks, we adds that only when it’s needed.
However, GB has the global max-width option at dashboard> generateblocks > settings.
Let me know if that works for you.
it’s very usefull because with a max width wrapper set on the theme, when I use a full width block/container and an inner container, to keep the same width of the template theme, it’s necessary set the max width on inner container.
So it works?
what?
I Just need something like a GB filter to set the global max width by code….
You can set the global max width in GB’s setting, that doesn’t work?
Maybe I didn’t explain myself well, sorry but I’m not English. I’ll try to explain myself better, I Simply need to set the global max-width value via code in dashboard> generateblocks> settings
I’m not sure I understand, but you can give this filter a try:
-
This reply was modified 1 year, 11 months ago by
ying.
yes It works but i don’t want set It manually because I already have to set It in my custom theme option, so I just want set it once, and automatically set it into gb
instead of a get function Is there a set function? Or maybe you can read It from theme.json?
Hi there,
If you defined the max-width value inside the settings array in
theme.json, you can try using thewp_get_global_settingsfunction to retrieve the value.Or, why not just use the
generateblocks_global_container_widthfilter hook and return the max-width value you set? That is simpler in my opinion.I can’t find
generateblocks_global_container_width, hoe use It?however I want to set global width automatically Reading a value from my theme option
The link I provided should take you right to the line 1193 of the GB file, and the filter
generateblocks_global_container_widthshould be on that line.You can do something like this:
add_filter('generateblocks_global_container_width', function() {
return 1500;
});Or you can add your own function which fetch your theme’s max-width to the filter.
It works! the only small problem is that the set value is visible in the blocks but in the settings is not read and whatever value is then entered on the settings page is not read.
Is there no way to enter the value in the db or in the settings page? -
This reply was modified 1 year, 11 months ago by
The topic ‘Set global max-width by code for custom theme’ is closed to new replies.