WordPress customizer : style chooser

I started working with scss bootstrap variables : very easy now to build dozens of color variations for your favorite all in one theme. Imagine you have ten stylesheets to choose from : you can reuse the same theme everywhere and concentrate on color choosing. Here is the piece of code for wordpress customizer that will allow you to select a stylesheet (named main-something.css) among all available from the dist / style folder !!

function wave_customizer_design_section( $wp_customize ) {
$wp_customize->add_section(
'wave_design',
array(
'title' => 'Design',
'description' => 'Design Rocks.',
'priority' => 35,
)
);

    $wp_customize->add_setting(
        'wave_style',
        array(
            'default' => 'wordpress',
        )
    );
    $styledir=scandir(get_stylesheet_directory(). "/dist/styles/");$arrStyles=array();
    foreach ($styledir as $k=>$value)
    {
        $fileinfo= pathinfo($value);
        if (strstr($value, "main") && $fileinfo["extension"] == "css") $arrStyles[$value]=$value;
    }
    $wp_customize->add_control(
        'wave_style',
        array(
            'type' => 'select',
            'label' => 'This site is powered by:',
            'section' => 'wave_design',
            'choices' => $arrStyles
        )
    );
}
add_action( 'customize_register', 'wave_customizer_design_section' );

 

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *