Site logo

[Resolved] GenerateBlocks/ Buttons / Customizer

Home Forums Support [Resolved] GenerateBlocks/ Buttons / Customizer

Home Forums Support GenerateBlocks/ Buttons / Customizer

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #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,
    Jan

    #1860072
    David
    Staff
    Customer Support

    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.

    #1860334
    Jan

    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

    #1860675
    David
    Staff
    Customer Support

    Try the value you added in the Global Style field:

    https://www.screencast.com/t/rDtWxAueu

    #1860694
    Jan

    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 ;-(

    #1860706
    David
    Staff
    Customer Support

    Its a GB Pro option found in Dashboard > GenerateBlocks:

    https://docs.generateblocks.com/article/global-styles/

    #1860729
    Jan

    Perfect. Thanks David

    #1860744
    David
    Staff
    Customer Support

    You’re welcome!

    #2561733
    Elvis

    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

    #2562719
    David
    Staff
    Customer Support

    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;
    } );
    #2563657
    Elvis

    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.

    #2563976
    David
    Staff
    Customer Support

    Glad to hear that!

Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.