这里有一种方法可以通过扩展要使用的控件来实现。
下面是一个扩展文本控件并添加额外描述的示例,如屏幕截图上所示:
function mytheme_customizer( $wp_customize ) {
class Custom_Text_Control extends WP_Customize_Control {
public $type = \'customtext\';
public $extra = \'\'; // we add this for the extra description
public function render_content() {
?>
<label>
<span><?php echo esc_html( $this->extra ); ?></span>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<input type="text" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
</label>
<?php
}
}
$wp_customize->add_section(\'customtext_section\', array(
\'title\'=>__(\'My Custom Text\',\'mytheme\'),
)
);
$wp_customize->add_setting(\'mytheme_options[customtext]\', array(
\'default\' => \'\',
\'type\' => \'customtext_control\',
\'capability\' => \'edit_theme_options\',
\'transport\' => \'refresh\',
)
);
$wp_customize->add_control( new Custom_Text_Control( $wp_customize, \'customtext_control\', array(
\'label\' => \'My custom Text Setting\',
\'section\' => \'customtext_section\',
\'settings\' => \'mytheme_options[customtext]\',
\'extra\' =>\'Here is my extra description text ...\'
) )
);
}
add_action( \'customize_register\', \'mytheme_customizer\' ,10,1);
检查
WP_Customize_Control
类别:
https://github.com/WordPress/WordPress/blob/master/wp-includes/class-wp-customize-control.php
希望这有帮助。