Add a text input in customizer in Wordpress 2019

    By: Thad Mertz
    4 years ago
    //add the code in functions.php
    
        
    
    add_action( 'customize_register', 'register_theme_customizer' );
    /*
     * Register Our Customizer Stuff Here
     */
    function register_theme_customizer( $wp_customize ) {
        // Create custom panel.
        $wp_customize->add_panel( 'text_blocks', array(
            'priority'       => 500,
            'theme_supports' => '',
            'title'          => __( 'Home Page Heading' ),
            'description'    => __( 'Anything You Add Here Will Display On Home Page.' ),
        ) );
        // Add Footer Text
        // Add section.
        $wp_customize->add_section( 'custom_footer_text' , array(
            'title'    => __('Change Home Page Heading Text'),
            'panel'    => 'text_blocks',
            'priority' => 10
        ) );
        
        // Add setting
        $wp_customize->add_setting( 'footer_text_block', array(
             'default'           => __( 'default text' ),
             'sanitize_callback' => 'sanitize_text'
        ) );
        // Add control
        $wp_customize->add_control( new WP_Customize_Control(
            $wp_customize,
            'custom_footer_text',
                array(
                    'label'    => __( 'Footer Text' ),
                    'section'  => 'custom_footer_text',
                    'settings' => 'footer_text_block',
                    'type'     => 'text'
                )
            )
        );
         // Sanitize text
        function sanitize_text( $text ) {
            return sanitize_text_field( $text );
        }
    }
    
    
    Now to display output in the front end
    
    <?php echo get_theme_mod( 'footer_text_block'); ?>