• function wf_customize_register( $wp_customize ) {
    
        // Colour Schemes
        $wp_customize->add_section('colour_scheme', array(
            'title'    => __('Colour Scheme', 'wf'),
            'priority' => 200,
        ));
    
        $wp_customize->add_setting('wf_theme_options[colour_scheme]', array(
            'default'        => 'jungle',
            'type'           => 'option',
            'capability'     => 'edit_theme_options',
        ));
    
        $wp_customize->add_control('colour_scheme', array(
            'label'      => __('Colour Scheme', 'wf'),
            'section'    => 'colour_scheme',
            'settings'   => 'wf_theme_options[colour_scheme]',
            'type'       => 'radio',
            'choices'    => array(
                'jungle' => 'Jungle',
                'sea' => 'Sea',
                'mountain' => 'Mountain',
                'woods' => 'Woods',
                'desert' => 'Desert',
            ),
        ));
    }
    add_action( 'customize_register', 'wf_customize_register' );
    
    function wf_customize_css()
    {
    	$mods = get_theme_mods();
    	var_dump($mods);
    
    	$skin = get_theme_mod('wf_theme_options');
        ?>
        	<link rel="stylesheet" href="<?php bloginfo('template_directory') ?>/css/<?php echo $skin ?>.css" />
        <?php
    }
    add_action( 'wp_head', 'wf_customize_css');

    I’m using customize_register( $wp_customize ) to add a skin/colour scheme option to my theme but don’t know how to grab the value from the radio button in the menu.

    When I do a var_dump, the output contains: ["wonderfort_theme_options"]=> array(1) { ["colour_scheme"]=> string(3) "sea" }

    How do I grab the ‘sea’ to use where $skin is? Currently it echos ‘Array’.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Laura Fischer

    (@limniad)

    Oops, all of the ‘wf’ in the php is actually ‘wonderfort’, just forgot to edit it out of the last lines.

    Moderator bcworkz

    (@bcworkz)

    Your var_dump (of $skin I assume) does not indicate if ["wonderfort_theme_options"] is from an array or object. If an array, the reference is $skin['wonderfort_theme_options']['colour_scheme'] and if object it is $skin->wonderfort_theme_options['colour_scheme']

    If I wrongly assumed something and neither one works, trying various similar combinations should yield something. With complex structures I’ve resorted to var_dumps of each subsequent level to determine the correct reference.

    Thread Starter Laura Fischer

    (@limniad)

    Thanks! $skin was already grabbing the wonderfort_theme_options array so using $skin['colour_scheme'] did the trick.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Use radio value from $wp_customize->add_control in function’ is closed to new replies.