Dynamically switch file in get_template_directory_uri() | Function

I need to switch scheme color of my WordPress theme trough Redux option panel.

My plan is switch the CSS file trough get_template_directory_uri() | Function.

The scenario is:

  1. Create 2 scheme color: dark and light with dark.css and libght.css.

  2. Control from redux panel with this code:

    ?php
    Redux::setSection( $opt_name, array(
     'title'  = __( 'Color Scheme', 'javapaper' ),
     'id'     = 'test_scheme',
     'icon'   = 'el el-list',
     'fields' = array(
         array(
             'id'       = 'color_scheme',
             'type'     = 'image_select',
             'title'    = __( 'SELECT Color Scheme', 'javapaper' ),
             'subtitle' = __( '2 scheme Available', 'javapaper' ),              
             'options'  = array(
                 'dark' = array(
                     'title' = 'dark',
                     'alt' = 'dark',
                     'img' = get_stylesheet_directory_uri() . '/images/header-styledefault.png'
                 ),              
                 'light' = array(
                     'title' = 'light',                 
                     'alt' = 'light',
                     'img' = get_stylesheet_directory_uri() . '/images/header-style2.png'
                 )                   
             ),
    
             'default'  = 'dark'
         ),          
    
          )
      ) );
    ?   
    
  3. Call the code from Redux panel into get_template_directory_uri() | Function like this:

     wp_enqueue_style( 'javapaper-lightbox-style', get_template_directory_uri() . '/css/$redux_demo[color_scheme]' );  
    

But Unfortunately It did not work. I am newbie on php. Please help.

Topic theme-options functions php theme-development themes Wordpress

Category Web


If you are sure that $redux_demo["color_scheme"] is getting the corresponding value, so your code should be:

global $redux_demo;
wp_enqueue_style( 'javapaper-lightbox-style', get_template_directory_uri() . "/css/{$redux_demo['color_scheme']}.css" );

Assuming that you have files in this structure css/dark.css and css/light.css.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.