-
Notifications
You must be signed in to change notification settings - Fork 0
CSS Output
Automatically output the setting as CSS by adding css argument like shown below:
'formFontSize' => [
'label' => __( 'Input Font Size' ),
'type' => 'ct-slider',
'units' => [
'px' => [ 'min' => 14, 'max' => 24 ],
],
'css' => '--formFontSize'
]By default, it will be applied to :root selector
:root {
--formFontSize: 18px;
}It will also add a toggle below the setting that reveals the CSS var name:
Add css_selector argument to parent section:
add_filter( 'h_customizer_options', function( $sections ) {
return wp_parse_args( [ 'form' => [
'title' => __( 'Form' ),
'container' => [ 'priority' => 10 ],
'css_selector' => 'form',
'options' => [
'formFontColor' => [ ... ],
'formFontSize' => [ ... ],
]
] ], $sections );
} );Now all the options under that section will be applied to form selector.
form {
--formFontColor: var(--text);
--formFontSize: 18px;
}It will also add a description below the Section's title showing what the selector is:
The css_selector argument can also be applied to any option to override the one from parent section:
'formFontSize' => [
'label' => __( 'Input Font Size' ),
'type' => 'ct-slider',
'units' => [
'px' => [ 'min' => 14, 'max' => 24 ],
],
'css_selector' => 'input',
'css' => '--formFontSize'
]Now the selector for --formFontSize is at input. But the other options still stay at form.
Options like Color Picker can have multiple values in one setting. In that case, the css argument has to be multiple too:
'formFontColor' => [
'label' => __( 'Input Font Color' ),
'type' => 'ct-color-picker',
'pickers' => [
'default' => __( 'Initial' ),
'focus' => __( 'Focus' ),
],
'css' => [
'--formFontColor': 'default.color',
'--formFontColorFocus': 'focus.color'
]
],The value default.color is array notation to get the value.
Where to apply the code above?
- The option snippet is for New Section Filter
- The value format is for Default Value Filter
Learn more:
