200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > php源码 自定义字段 wordpress主题制作:设置自定义选项字段

php源码 自定义字段 wordpress主题制作:设置自定义选项字段

时间:2018-12-11 16:43:37

相关推荐

php源码 自定义字段 wordpress主题制作:设置自定义选项字段

在主题制作时,有时需要将一些文字和样式提出来,做成一个选项给用户设置。

customize_register这个可以帮到你

定义一个可编辑内容,并且可以设置颜色。代码如下,必须在functions.php中

/*注册 customize*/

add_action('customize_register', 'theme_footer_customizer');

function theme_footer_customizer($wp_customize){

//adding section in wordpress customizer

$wp_customize->add_section('user_settings_section', array(

'title' => '文字设置'

));

//adding setting for footer text area

$wp_customize->add_setting('text_setting', array(

'default' => '默认文字',

));

$wp_customize->add_control('text_setting', array(

'label' => '内容',

'section' => 'user_settings_section',

'type' => 'textarea',

));

$wp_customize->add_setting( 'text_color' , array(

'default' => '#000000',

'transport' => 'refresh',

));

$wp_customize->add_control(

new WP_Customize_Color_Control(

$wp_customize,

'header_color',

array(

'label' => '字体颜色',

'section' => 'user_settings_section',

'settings' => 'text_color',

))

);

}

模板中

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。