Add custom field in customizer

PHOTO EMBED

Wed Sep 18 2024 05:07:00 GMT+0000 (Coordinated Universal Time)

Saved by @hamzahanif192

function customizer_register_cta_settings($wp_customize) {
    // Add a section for the CTA
    $wp_customize->add_section('cta_section', array(
        'title'    => __('CTA Settings', 'textdomain'),
        'priority' => 30,
    ));

    // Add a setting for the CTA Title
    $wp_customize->add_setting('cta_title', array(
        'default'           => __('If You Need Any Help Contact With Us', 'textdomain'),
        'sanitize_callback' => 'sanitize_text_field',
    ));

    // Add a control for the CTA Title
    $wp_customize->add_control('cta_title_control', array(
        'label'    => __('CTA Title', 'textdomain'),
        'section'  => 'cta_section',
        'settings' => 'cta_title',
        'type'     => 'text',
    ));

    // Add a setting for the phone number
    $wp_customize->add_setting('cta_phone_number', array(
        'default'           => __('343.909.3074', 'textdomain'),
        'sanitize_callback' => 'sanitize_text_field',
    ));

    // Add a control for the phone number
    $wp_customize->add_control('cta_phone_number_control', array(
        'label'    => __('Phone Number', 'textdomain'),
        'section'  => 'cta_section',
        'settings' => 'cta_phone_number',
        'type'     => 'text',
    ));
}

add_action('customize_register', 'customizer_register_cta_settings');
content_copyCOPY