- This topic has 11 replies, 3 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
July 18, 2021 at 7:05 am #1859783
Jan
Hi Leo,
I’d like to style all buttons (GenerateBlocks) in the same fashion across the site. To find out how I went through this documentation:
https://docs.generateblocks.com/article/buttons-overview/#colors
This, however, only talks about how to style each button or a group of buttons in one place.
So far customizer color-setting in the Customizer only change the WP standard button blocks across the site. How can I enable Customizer settings to also apply to the GenerateBlocks buttons?
Thanks,
JanJuly 18, 2021 at 8:39 am #1860072David
StaffCustomer SupportHi there,
we’re working on integration for button styles in a future update.
In the meantime it takes a bit of code to set the GB button defaults.Heres a topic related to that in our GB Community:
https://community.generateblocks.com/t/using-global-styles-by-default/74
Worth joining the community and asking how to do it there – and we can provide the snippets for that.
July 18, 2021 at 3:26 pm #1860334Jan
Hi David,
I added the following to the function.php of the child theme:
add_filter( 'generateblocks_defaults', function( $defaults ) { $defaults['button']['useGlobalStyle'] = true; $defaults['button']['globalStyleId'] = '<strong>your-global-style-id</strong>'; return $defaults; } ); add_filter( 'generateblocks_default_block_styles', function( $styles ) { $styles['button']['backgroundColor'] = ''; $styles['button']['textColor'] = ''; $styles['button']['backgroundColorHover'] = ''; $styles['button']['textColorHover'] = ''; $styles['button']['paddingTop'] = ''; $styles['button']['paddingRight'] = ''; $styles['button']['paddingBottom'] = ''; $styles['button']['paddingLeft'] = ''; return $styles; } );I understand that a “your-global-style-id” needs to be added before the filter works.
Where do I find this id?
Many thanks,
JanJuly 19, 2021 at 1:58 am #1860675David
StaffCustomer SupportTry the value you added in the Global Style field:
July 19, 2021 at 2:21 am #1860694Jan
Many thanks David.
May I ask you to point me to the documentation regarding “Global Style”?
I checked the config of GenerateBlocks but I don’t see this Global Style field when I click on the button block on my test page ;-(
July 19, 2021 at 2:34 am #1860706David
StaffCustomer SupportIts a GB Pro option found in Dashboard > GenerateBlocks:
July 19, 2021 at 2:55 am #1860729Jan
Perfect. Thanks David
July 19, 2021 at 3:09 am #1860744David
StaffCustomer SupportYou’re welcome!
March 9, 2023 at 7:55 am #2561733Elvis
Hello David
I am trying the following.
I have 4 styles for my buttons.
gb-button-dark-fill
gb-button-light-fill
gb-button-dark-outline
gb-button-light-outlineI want my to be the default for each button someone inserts into the site.
SO I first clear the default styles like this:
// Clear Default styles on GenerateBlocks add_filter( 'generateblocks_default_block_styles', function( $styles ) { $styles['button']['backgroundColor'] = ''; $styles['button']['textColor'] = ''; $styles['button']['backgroundColorHover'] = ''; $styles['button']['textColorHover'] = ''; $styles['button']['paddingTop'] = ''; $styles['button']['paddingRight'] = ''; $styles['button']['paddingBottom'] = ''; $styles['button']['paddingLeft'] = ''; return $styles; } );Then I assign the global style as the default
// Set the Defalts per Block Type add_filter( 'generateblocks_defaults', function( $defaults ) { $defaults['button']['useGlobalStyle'] = true; // Set the Defalts per Block Type add_filter( 'generateblocks_defaults', function( $defaults ) { $defaults['button']['useGlobalStyle'] = true; $defaults['button']['globalStyleId'] = 'fill-dark'; return $defaults; } ); = 'fill-dark'; return $defaults; } );I have tried to reverse the order of the two functions, I have tried to change the value of
$defaults['button']['globalStyleId']to ‘gb-button-dark-fill’ as well. I have also tryed to remove the generateblocks_default_block_styles filter. In neither case does it work. The generateblocks_default_block_styles works in all these cases, but generateblocks_defaults does not.What am I missing?
Thanks
March 10, 2023 at 3:58 am #2562719David
StaffCustomer SupportHi there,
does this work ?
add_filter( 'generateblocks_defaults', function( $defaults ) { $defaults['button']['useGlobalStyle'] = true; $defaults['button']['globalStyleId'] = 'fill-dark'; return $defaults; } ); add_filter( 'generateblocks_default_block_styles', function( $styles ) { $styles['button']['backgroundColor'] = ''; $styles['button']['textColor'] = ''; $styles['button']['backgroundColorHover'] = ''; $styles['button']['textColorHover'] = ''; $styles['button']['paddingTop'] = ''; $styles['button']['paddingRight'] = ''; $styles['button']['paddingBottom'] = ''; $styles['button']['paddingLeft'] = ''; return $styles; } );March 10, 2023 at 8:54 pm #2563657Elvis
Hi, it does work. The issue was actually in me using WPCodeBox to write code. The Default hook was too late (or too early) so when changing to init, it does the trick. Thanks.
March 11, 2023 at 7:07 am #2563976David
StaffCustomer SupportGlad to hear that!
-
AuthorPosts
- You must be logged in to reply to this topic.