Title: GenerateBlocks defaults
Last modified: March 20, 2025

---

# GenerateBlocks defaults

 *  Resolved [fkoomek](https://wordpress.org/support/users/fkoomek/)
 * (@fkoomek)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/generateblocks-defaults/)
 * Hello.
   I am trying to set some defaults, for example for a button. I found this
   code [here](https://generatepress.com/forums/topic/add-custom-css-selector-to-the-button-selector/#post-1322768)
 *     ```wp-block-code
       add_filter( 'generateblocks_defaults', function( $defaults ) { $color_settings = wp_parse_args( get_option( 'generate_settings', array() ), generate_get_color_defaults() ); $defaults['button']['backgroundColor'] = $color_settings['form_button_background_color']; $defaults['button']['backgroundColorHover'] = $color_settings['form_button_background_color_hover']; $defaults['button']['textColor'] = $color_settings['form_button_text_color']; $defaults['button']['textColorHover'] = $color_settings['form_button_text_color_hover']; $defaults['button']['paddingTop'] = '10'; $defaults['button']['paddingRight'] = '20'; $defaults['button']['paddingBottom'] = '10'; $defaults['button']['paddingLeft'] = '20'; return $defaults; } );
       ```
   
 * But it’s not working.
   Then I tried this filter
 *     ```wp-block-code
       add_filter( 'generateblocks_default_button_attributes', function( $attributes ) {return $attributes;}
       ```
   
 * Which works but not on initial inserting of the element in Gutebnerg, only after
   saving or opening block settings. Is it somehow possible to set correctly the
   defaults?
   Thank you.Radan
    -  This topic was modified 1 year, 2 months ago by [fkoomek](https://wordpress.org/support/users/fkoomek/).
    -  This topic was modified 1 year, 2 months ago by [fkoomek](https://wordpress.org/support/users/fkoomek/).

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/generateblocks-defaults/#post-18373272)
 * Hi there,
 * Are you using v2 blocks now?
 * If so, try this instead:
 *     ```wp-block-code
       add_filter( 'generateblocks_default_button_attributes', function() {    $color_settings = wp_parse_args(        get_option( 'generate_settings', array() ),        generate_get_color_defaults()    );    return [        'styles' => [            'display' => 'inline-flex',            'alignItems' => 'center',            'backgroundColor' => $color_settings['form_button_background_color'],            'color' => $color_settings['form_button_text_color'],            'paddingTop' => '1rem',            'paddingRight' => '2rem',            'paddingBottom' => '1rem',            'paddingLeft' => '2rem',            'textDecoration' => 'none',            '&:is(:hover, :focus)' => [            'backgroundColor' => $color_settings['form_button_background_color_hover'],            'color' => $color_settings['form_button_text_color_hover'],	],        ],    ];} );
       ```
   
 *  Thread Starter [fkoomek](https://wordpress.org/support/users/fkoomek/)
 * (@fkoomek)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/generateblocks-defaults/#post-18373292)
 * Hello.
   Thank you for your reply.I am using the latest version 2.0.1 but your 
   code unfortunately doesn’t workRadan
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/generateblocks-defaults/#post-18373351)
 * I’ve updated my code, please give it another try.
 *  Thread Starter [fkoomek](https://wordpress.org/support/users/fkoomek/)
 * (@fkoomek)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/generateblocks-defaults/#post-18373409)
 * That did it. Many thanks 🤝
   Radan
    -  This reply was modified 1 year, 2 months ago by [fkoomek](https://wordpress.org/support/users/fkoomek/).
 *  Plugin Support [ying](https://wordpress.org/support/users/yingscarlett/)
 * (@yingscarlett)
 * [1 year, 2 months ago](https://wordpress.org/support/topic/generateblocks-defaults/#post-18375110)
 * You are welcome   🙂

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘GenerateBlocks defaults’ 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/)

 * 5 replies
 * 2 participants
 * Last reply from: [ying](https://wordpress.org/support/users/yingscarlett/)
 * Last activity: [1 year, 2 months ago](https://wordpress.org/support/topic/generateblocks-defaults/#post-18375110)
 * Status: resolved