Title: Set global max-width by code for custom theme
Last modified: June 24, 2024

---

# Set global max-width by code for custom theme

 *  [Stefano](https://wordpress.org/support/users/stefacchio/)
 * (@stefacchio)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/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

Viewing 15 replies - 1 through 15 (of 22 total)

1 [2](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/page/2/?output_format=md)

 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847104)
 * 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 🙂
 *  Thread Starter [Stefano](https://wordpress.org/support/users/stefacchio/)
 * (@stefacchio)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847319)
 * 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](https://wordpress.org/support/users/stefacchio/).
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847348)
 * 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.
 *  Thread Starter [Stefano](https://wordpress.org/support/users/stefacchio/)
 * (@stefacchio)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847364)
 * 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.
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847498)
 * So it works?
 *  Thread Starter [Stefano](https://wordpress.org/support/users/stefacchio/)
 * (@stefacchio)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847536)
 * what?
 * I Just need something like a GB filter to set the global max width by code….
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847538)
 * You can set the global max width in GB’s setting, that doesn’t work?
 *  Thread Starter [Stefano](https://wordpress.org/support/users/stefacchio/)
 * (@stefacchio)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847541)
 * 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
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847543)
 * I’m not sure I understand, but you can give this filter a try:
 * [https://github.com/tomusborne/generateblocks/blob/37ef046964d3bd40f573c7f11534e932cae92300/includes/functions.php#L1193](https://github.com/tomusborne/generateblocks/blob/37ef046964d3bd40f573c7f11534e932cae92300/includes/functions.php#L1193)
    -  This reply was modified 1 year, 11 months ago by [ying](https://wordpress.org/support/users/yingscarlett/).
 *  Thread Starter [Stefano](https://wordpress.org/support/users/stefacchio/)
 * (@stefacchio)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847544)
 * 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
 *  Thread Starter [Stefano](https://wordpress.org/support/users/stefacchio/)
 * (@stefacchio)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847555)
 * instead of a get function Is there a set function? Or maybe you can read It from
   theme.json?
 *  Plugin Support [Alvind](https://wordpress.org/support/users/alvindcaesar/)
 * (@alvindcaesar)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17847668)
 * Hi there,
 * If you defined the max-width value inside the settings array in `theme.json`,
   you can try using the `wp_get_global_settings` function to retrieve the value.
 * Or, why not just use the `generateblocks_global_container_width` filter hook 
   and return the max-width value you set? That is simpler in my opinion.
 *  Thread Starter [Stefano](https://wordpress.org/support/users/stefacchio/)
 * (@stefacchio)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17850251)
 * 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
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17850313)
 * The link I provided should take you right to the line 1193 of the GB file, and
   the filter `generateblocks_global_container_width` should be on that line.
 * You can do something like this:
 *     ```wp-block-code
       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.
 *  Thread Starter [Stefano](https://wordpress.org/support/users/stefacchio/)
 * (@stefacchio)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/#post-17851829)
 * 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?

Viewing 15 replies - 1 through 15 (of 22 total)

1 [2](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/page/2/?output_format=md)

The topic ‘Set global max-width by code for custom theme’ is closed to new replies.

 * ![](https://ps.w.org/generateblocks/assets/icon.svg?rev=3239461)
 * [GenerateBlocks](https://wordpress.org/plugins/generateblocks/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/generateblocks/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/generateblocks/)
 * [Active Topics](https://wordpress.org/support/plugin/generateblocks/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/generateblocks/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/generateblocks/reviews/)

## Tags

 * [custom theme](https://wordpress.org/support/topic-tag/custom-theme/)
 * [max-width](https://wordpress.org/support/topic-tag/max-width/)

 * 22 replies
 * 3 participants
 * Last reply from: [Alvind](https://wordpress.org/support/users/alvindcaesar/)
 * Last activity: [1 year, 11 months ago](https://wordpress.org/support/topic/set-global-max-width-by-code-for-custom-theme/page/2/#post-17857857)
 * Status: not resolved