Skip to content

Type – Condition

Henner R Setyono edited this page Mar 19, 2020 · 5 revisions

Wrap other options to only appear when the condition is fulfilled

custy_rand_id() => [
  'condition' => [ 'sidebar_type' => 'type-2 | type-4' ],
  'options' => [
    'option1' => [ ... ],
    'option2' => [ ... ],
  ],
],

condition

  • Accepts an array of option_id and it's expected value.

Various Format

  1. Value is NOT something

    'condition' => [ 'button_style' => '!solid' ],
  2. Condition for Checkboxes.

    For example: we have checkboxes called tease_elements to select what to show in a Post Listing. The options are title, excerpt, featured_image, published_date, and author.

    Now we want an option to only appear if author is ticked. So we write it like this:

    'condition' => [ 'tease_elements/author' => true ]
  3. Must fulfill MULTIPLE conditions

    'condition' => [
      'tease_elements/title' => true,
      'tease_elements/excerpt' => true
    ]
  4. At least fulfill ONE condition

    'condition' => [ 'any' => [
      'tease_elements/title' => true,
      'tease_elements/excerpt' => true
    ] ]
  5. Condition on Current Preview Size

    'condition' => [ 'wp_customizer_current_view' => 'mobile' ]
    

Clone this wiki locally