gform_default_styles

Description

The gform_default_styles filter can be used to filter the global form theme styles.

Usage

Applies to all forms:

add_filter( 'gform_default_styles', 'your_function_name' );

Note: When using this filter, it may be necessary to click Reset Defaults on a form block in order to see changes take effect.

Parameters

// acceptable properties
'theme'
'inputSize'
'inputBorderRadius'
'inputBorderColor'
'inputBackgroundColor'
'inputColor'
'inputPrimaryColor'
'labelFontSize'
'labelColor'
'descriptionFontSize'
'descriptionColor'
'buttonPrimaryBackgroundColor'
'buttonPrimaryColor'

Examples

1. Set default button colors based on theme.json element

This example shows how you can set default Gravity Forms button styles based on style settings in your theme.json file. Note that this example makes no checks for existence of the file or of the specific values.

add_filter( 'gform_default_styles', function( $styles ) {
    
    $theme_json = json_decode( file_get_contents( get_template_directory() . '/theme.json' ), JSON_OBJECT_AS_ARRAY );

    $styles['buttonPrimaryBackgroundColor'] = rgars( $theme_json, 'styles/elements/button/color/background' );
    $styles['buttonPrimaryColor'] = rgars( $theme_json, 'styles/elements/button/color/text' );

    return $styles;

} );

2. Set default styles based on those copied from Gravity Forms block

add_filter( 'gform_default_styles', function( $styles ) {
	return '{"theme":"","inputSize":"md","inputBorderRadius":"20","inputBorderColor":"#0693e3","inputBackgroundColor":"#fff","inputColor":"#112337","inputPrimaryColor":"#204ce5","labelFontSize":"20","labelColor":"#112337","descriptionColor":"#585e6a","buttonPrimaryBackgroundColor":"#7700e6","buttonPrimaryColor":"#fff"}';
} );

Placement

This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.

See also the PHP section in this article: Where Do I Put This Code?

Since

This filter was added in Gravity Forms 2.7.15

Source Code

This filter is located in class GFFormDisplay in /form_display.php and in class GF_Blocks_Service_Provider in /includes/blocks/class-gf-blocks-service-provider.php.