我无法弄清楚如何从 WP 自定义管理器中的复选框中获取值 - 无论是否选中它们。
这是functions.php中的代码:
$wp_customize->add_setting('social_facebook', array(
'type' => 'option',
));
$wp_customize->add_control(
new WP_Customize_Control(
$wp_customize,
'social_facebook',
array(
'label' => __( 'Facebook', 'theme_name' ),
'section' => 'social-icons',
'settings' => 'social_facebook',
'type' => 'checkbox',
)
)
);
Run Code Online (Sandbox Code Playgroud)
这就是我尝试获取价值的方式:
<?php
$facebook = get_theme_mod('social_facebook');
if ($facebook != ''){?>
<style>
.facebook {display:inline!important;}
</style>
<?php }
?>
Run Code Online (Sandbox Code Playgroud)
复选框的值是“”(空)或“1”,因此系统会注册它们的检查。但是,我不知道如何通过 get_theme_mod 方法获取值。此外,它们没有任何名称值,因此我也无法通过通常的方式获取该值。