Archived topic
GenerateBlocks/ Buttons / Customizer
11 replies · Started by Jan on July 18, 2021
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,
Jan
Hi 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.
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,
Jan
Try the value you added in the Global Style field:
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 ;-(
Its a GB Pro option found in Dashboard > GenerateBlocks:
Perfect. Thanks David
You're welcome!
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-outline
I 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
Hi 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;
} );
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.
Glad to hear that!