php WP - 创建主题选项Customizer API

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php WP - 创建主题选项Customizer API相关的知识,希望对你有一定的参考价值。

<?php

/*
Create theme option customizer

Using customize register API

** section_id_show_test : Id Of section
** af_text_1 : Id of input

*/

function ghled_customize_register($wp_customize){

  //This adds a new setting to the database.
  $wp_customize->add_section('section_id_show_test', array(
        'title'    => __('Inputs for test', 'textdomaine'),
        'description' => '',
        'priority' => 120,
    ));
 
  //This adds a new section (i.e. category/group) to the Theme Customizer page.
    //  =============================
    //  = Text Input                =
    //  =============================
    $wp_customize->add_setting('af_text_1', array(
        'default'        => 'value_xyz',
        'capability'     => 'edit_theme_options',
        'type'           => 'option',
 
    ));
 
  //This creates an HTML control that admins can use to change settings. This is also where you choose a section for the control to appear in.
    $wp_customize->add_control('id_controle_text_1', array(
        'label'      => __('Text Test', 'textdomaine'),
        'section'    => 'section_id_show_test',
        'settings'   => 'af_text_1',
    ));
  
}
//Hooking function
add_action('customize_register', 'ghled_customize_register');


/*

Retrieving by : get_option(;

*/
//get_option('af_text_1');
$str1 = get_option('af_text_1');
var_dump($str1);

以上是关于php WP - 创建主题选项Customizer API的主要内容,如果未能解决你的问题,请参考以下文章

wordpress如何让自己的主题支持菜单功能

php GA跟踪代码 - 如果选项为is_user_logged_in - is_customize_preview

php 删除主题的WP版本

php WP-主题定制寄存器空

php WP - 翻译主题

php WP片段(HTML,内部主题)