Search code examples
phpwordpressredux-framework

Redux Wordpress Framework enqueue style


I use the redux framework in my wordpress theme.

My global variable is $ua_options

So I created a switch in my config.php:

array(
   'id'       => 'ua-enable-responsive',
   'type'     => 'switch',
   'title'    => __( 'Responsive', 'redux-framework-demo' ),
   'compiler' => 'true',
   'mode'     => false,
),

In my functions.php I want to enqueue a file conditionally:

if ($ua_options['ua-enable-responsive']) {
    wp_enqueue_style( 'mytheme-bootstrap', get_template_directory_uri() . '/css/bootstrap.css'      );
}
else {
    wp_enqueue_style( 'mytheme-non-responsive', get_template_directory_uri() . '/css/no-responsive.css' );      
}

But that doesn't seem to work. The second file no-responsive.css gets always loaded no matter if I turn the switch to on in the backend.

I also called the global variable at the top of my functions.php

global $ua_options;

Does somebody have an Idea why this wont work? Also is there a way to show such errors / warnings?


Solution

  • Lead dev of Redux here. You need to call your Redux config BEFORE you load this code. If you can't do that, then you have to do a get_option('opt_name') to get the values.

    Basically I bet you'll find that $us_options is empty because it hadn't been created yet. ;)