以下是可行的解决方案(主题名为“zoran”):
//1. Step (Create Customizer section, setting, control)
//In functions.php include or directly put code that goes something like this:
function zoran_customize_register( $wp_customize ) {
$wp_customize->add_section( \'zoran_sekcija\', array(
\'title\' => __( \'Zoran\', \'zoran\' ),
\'priority\' => 35,
) );
$wp_customize->add_setting( \'zoran_postavka\', array(
\'default\' => \'container\',
\'type\' => \'theme_mod\',
\'capability\' => \'edit_theme_options\',
) );
$wp_customize->add_control(\'zoran_control\', array(
\'label\' => \'Container\',
\'section\' => \'zoran_sekcija\',
\'settings\' => \'zoran_postavka\',
\'type\' => \'radio\',
\'choices\' => array(
\'container\' => \'Fluid\',
\'container-fluid\' => \'Fixed\',
),
) );
}
add_action( \'customize_register\', \'zoran_customize_register\' );
//2. Step (Create javascript to manipulate class container)
//In functions.php include or type:
function zoran_customize_js()
{
?>
<script>
div = document.getElementsByClassName("container");
div[0].classList.toggle(<?php echo "\'" . get_theme_mod(\'zoran_postavka\', \'container\') . "\'"; ?>);
</script>
<?php
}
add_action( \'wp_footer\', \'zoran_customize_js\');
我想就是这样。请提出改进建议。