明白了!这是对我有用的代码。
--主题自定义设置和控件(我的在单独的customizer.php
文件):
function themename_customize_register( $wp_customize ) {
...
$wpcustomize->add_setting( \'themename_skin\', array(
\'default\' => \'light\',
),
);
$wp_customize->add_control( \'themename_skin\', array(
\'label\' => \'Skin\',
\'section\' => \'colors\',
\'settings\' => \'themename_skin\',
\'type\' => \'radio\',
\'choices\' => array(
\'light\' => \'Light\',
\'dark\' => \'Dark\',
),
)
);
...
}
add_action( \'customize_register\', \'themename_customize_register\' );
--将亮/暗样式表排队
functions.php
以及其他脚本/样式:
function themename_scripts() {
...
/* Enqueue the appropriate CSS based on which skin is selected via Theme Customizer */
$skin = get_theme_mod( \'themename_skin\' );
if ( $skin == \'light\' ) {
wp_enqueue_style( \'themename-light-skin\', get_template_directory_uri() . \'/skins/light.css\' );
}
if ( $skin == \'dark\' ) {
wp_enqueue_style( \'themename-dark-skin\', get_template_directory_uri() . \'/skins/dark.css\' );
}
...
}
add_action( \'wp_enqueue_scripts\', \'themename_scripts\' );
感谢
cale_b 为我指明了正确的方向。