Skip to main content
All CollectionsDevelopers
Settings Field Visibility
Settings Field Visibility

Learn how to show or hide a setting depending on the value of other settings.

Updated over a week ago

Note: This tutorial series is intended for advanced users. An advanced understanding of coding in PHP and JavaScript is required.

The visibility of a module setting can depend on the value of other settings by including one or both of the parameters described below in the setting definition.

Setting Visibility Parameters

  • show_if (array)

    • setting (string|string[]) β€” Setting value(s)

  • show_if_not (array)

    • setting (string|string[]) β€” Setting value(s)

Setting Visibility Examples

Only show setting_a when:

  • setting_b is on

<?php

...

public function get_fields() {
return array(
'setting_a' => array(
'label' => esc_html__( 'Setting A', 'myex-my-extension' ),
'type' => 'text',
'option_category' => 'basic_option',
'description' => esc_html__( 'Input something here.', 'myex-my-extension' ),
'toggle_slug' => 'main_content',
'show_if' => array(
'setting_b' => 'on',
),
),
'setting_b' => array(
...
),
);
}

...

Only show setting_c when:

  • setting_b is on

  • AND setting_a is not some_value

<?php

...

public function get_fields() {
return array(
'setting_a' => array(
...
),
'setting_b' => array(
...
),
'setting_c' => array(
'label' => esc_html__( 'Setting C', 'myex-my-extension' ),
'type' => 'text',
'option_category' => 'basic_option',
'description' => esc_html__( 'Input something else here.', 'myex-my-extension' ),
'toggle_slug' => 'main_content',
'show_if' => array(
'setting_b' => 'on',
),
'show_if_not' => array(
'setting_a' => 'some value',
),
),
);
}

...

Only show setting_a when:

  • setting_b is one of value_1, value_3, value_4

  • AND setting_c is not some_value

  • AND setting_d is not one of value_1, value_4

<?php

...

public function get_fields() {
return array(
'setting_a' => array(
'label' => esc_html__( 'Setting A', 'myex-my-extension' ),
'type' => 'text',
'option_category' => 'basic_option',
'description' => esc_html__( 'Input something here.', 'myex-my-extension' ),
'toggle_slug' => 'main_content',
'show_if' => array(
'setting_b' => array( 'value_1', 'value_3', 'value_4' ),
),
'show_if_not' => array(
'setting_c' => 'some_value',
'setting_d' => array( 'value_1', 'value_4' ),
),
),
'setting_b' => array(
...
),
'setting_c' => array(
...
),
'setting_d' => array(
...
),
);
}

...
Did this answer your question?