php – WordPress Text Customizer Field returns 0-ThrowExceptions

Exception or error:

This is my first post on Stack Overflow!

So I am digging into the WordPress Customizer API, and can’t seem to get the hang of it. I have registered a text field, and have it working within the customizer, but as soon as I submit the value and check the front end, I get a “0” returning, no matter what I try. Is there something I am missing? Here is my code:

    function neu_customize_register( $wp_customize ) {

    $wp_customize->add_section( 'neuport_header_settings' , array(
        'title'      => __( 'Header Settings', 'neuport' ),
        'priority'   => 30,
    ) );

    $wp_customize->add_setting( 'header_text', array(
        'default'           => __( 'default text', 'neuport' ),
        'type'              => 'theme_mod',
        'capability' => 'edit_theme_options',
        'sanitize_callback' => 'our_sanitize_function',
   ) );

    // Add control
    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'neuport_header_settings',
            array(
                'label'    => __( 'Header Text', 'neuport' ),
                'section'  => 'neuport_header_settings',
                'settings' => 'header_text',
                'type'     => 'text'
            )
        )
    );
    function our_sanitize_function( $input ) {
        return wp_kses_post( force_balance_tags( $input ) );
    }
 }
 add_action( 'customize_register', 'neu_customize_register' );

Then, after that I am using this to display it on the front end:

    <h1 class="logo">
        <a href="<?php home_url(); ?>">
         <?php echo get_theme_mod( 'header_text'); ?>
        </a>
    </h1>

It is probably something right in front of my face, but I’m still so new to the customizer. I would really appreciate some help! Thanks everyone!

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *