最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

functions - How to create a field in customize and show that in header.php?

programmeradmin1浏览0评论

I am new to WordPress coding and learning this from stackexchange, I am trying to create one WordPress website from scratch, in header I want to show contact information for example phone number, I want to create a field in customize and want to display the value in header.php. Is there any guide or tutorial for that? Any help will be appreciated. Thanks a lot!! *don't want to use plugin

I am new to WordPress coding and learning this from stackexchange, I am trying to create one WordPress website from scratch, in header I want to show contact information for example phone number, I want to create a field in customize and want to display the value in header.php. Is there any guide or tutorial for that? Any help will be appreciated. Thanks a lot!! *don't want to use plugin

Share Improve this question asked Oct 28, 2020 at 5:48 RickyRicky 538 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1
add_action( 'customize_register', 'theme_customize_register' );


/**
 * Register individual settings through customizer's API.
 *
 * @param WP_Customize_Manager $wp_customize Customizer reference.
 */
function theme_customize_register( $wp_customize ) {

    // You can first start by adding a section
    
    $wp_customize->add_section(
        'theme_options',
        array(
            'title'       => __( 'Title of your section', 'domain' ),
            'capability'  => 'edit_theme_options',
            'description' => __( 'Some description', 'domain' ),
            'priority'    => 160,
        )
    );
    $wp_customize->add_setting(
        'field_name',
        array(
            'type'              => 'textarea',
            'sanitize_callback' => 'theme_sanitize_text', // You can sanitize the text afterwards through this function
            'capability'        => 'edit_theme_options',
        )
    );

}

In the API docs you can find also what other fields you can use and how you can modify them.

In order to access your settings you can use

get_theme_mod('field_name');

Make sure to add this to a plugin or child theme.

发布评论

评论列表(0)

  1. 暂无评论