2

how to use redux framework switch type in wordpress themes?

if ( $my_opt_name ) { do something }

or

if ( $my_opt_name === '1' ) { do something }

or

if ( $my_opt_name == '1' ) { do something }

or

if ( $my_opt_name == 1 ) { do something }

or

if ( $my_opt_name === 1 ) { do something }

or

if ( $my_opt_name == true ) { do something }

I worked with all of this and that works Properly but sometimes does not work.

Linda Paiste
  • 20,442
  • 2
  • 16
  • 40
ShahePars
  • 125
  • 2
  • 14

2 Answers2

1

You can follow this steps.

Step-1: use this type of code to add switch, and focus on id value.

$fields = array(
    'id'       => 'opt-switch',
    'type'     => 'switch', 
    'title'    => __('Switch On', 'redux-framework-demo'),
    'subtitle' => __('Look, it\'s on!', 'redux-framework-demo'),
    'default'  => true,
);

Step-2: Use this code to use switch

global $redux_demo;
if( $redux_demo['opt-switch']){
 //Do Something if switch is on(i.e - true)
}

Try that , then let me know the result. Thanks

Souvik Sikdar
  • 717
  • 5
  • 11
-1

This is the solution:

<?php global $redux_demo;?>
<?php if ( $redux_demo ['opt-switch'] == '1' ){ ?>
  <div class="row header-top">
    <div class="col-sm">
      <p>Header sections 1</p>
    </div><!-- .col-sm -->
    <div class="col-sm">
      <p>Header sections 2</p>
    </div><!-- .col-sm -->
    <div class="col-sm">
      <p>Header sections 3</p>
    </div><!-- .col-sm -->  
  </div><!-- .row -->   
<?php }?>
Ironcache
  • 1,679
  • 22
  • 31