-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If no value set – do not output css property #537
Comments
Same for colors and any other controls? |
You can perform a check on the Kirki::add_config( 'dummy_config' );
Kirki::add_field( 'dummy_config', array(
'type' => 'slider',
'settings' => 'my_setting',
'label' => __( 'Border width', 'translation_domain' ),
'section' => 'my_section',
'default' => 1,
'priority' => 1,
'choices' => array(
'min' => 0,
'max' => 20,
'step' => 1,
),
'output' => ( '1' != Kirki::get_option( 'dummy_config', 'my_setting' ) && !empty( Kirki::get_option( 'dummy_config', 'my_setting' ) ) ) ? array(
array(
'element' => '.variable-top-border',
'property' => 'border-top-width',
'units' => 'px',
),
array(
'element' => '.variable-bottom-border',
'property' => 'border-bottom-width',
'units' => 'px',
),
) : null,
) ); This checks against the Hope that helps. |
@pavot the solution suggested by @doitmax above is the recommended method. 'output' => ( ! empty( get_theme_mod( 'my_setting' ) ) ) ? array(
array(
'element' => '.variable-top-border',
'property' => 'border-top-width',
'units' => 'px',
),
array(
'element' => '.variable-bottom-border',
'property' => 'border-bottom-width',
'units' => 'px',
),
) : array(), |
@aristath Oh sorry, i have used the (still) wrong example from the Wiki. Of course it should be Cheers |
yeah, I've completely neglected updating the wiki.... lots of things I must change there. 😟 |
I get a Fatal error: Can't use function return value in write context in error because prior to PHP 5.5, empty() only supports variables; anything else will result in a parse error. Probably better: 'output' => ( get_theme_mod( 'my_setting' ) != '' ) ? array(
array(
'element' => '.variable-top-border',
'property' => 'border-top-width',
'units' => 'px',
),
array(
'element' => '.variable-bottom-border',
'property' => 'border-bottom-width',
'units' => 'px',
),
) : array(), Would you please confirm that? |
yes, but you can just get the value before creating the control and save it in a var for later use. $my_setting_value = get_theme_mod( 'my_setting', 1 );
Kirki::add_field( 'dummy_config', array(
'type' => 'slider',
'settings' => 'my_setting',
'label' => __( 'Border width', 'translation_domain' ),
'section' => 'my_section',
'default' => 1,
'priority' => 1,
'output' => ( ! empty( $my_setting_value ) ) ? array(
array(
'element' => '.variable-top-border',
'property' => 'border-top-width',
'units' => 'px',
),
) : array(),
) ); |
Is there a possibility to not output css property if the value is empty as shown on the screenshot: https://www.evernote.com/l/AAHOqSbXDWlJzaWorc2eacmzrQefmboArywB/image.png ?
Thanks for your time.
The text was updated successfully, but these errors were encountered: