Customizer options

I’m currently working on a WordPress theme. The design + functionality is already done and it’s activated. But this is my first day of creating themes for WordPress (hello, new friends) and I’m unsure how to create a customizer option.

I’ve checked various tutorials and I understand the code they put in there, but I don’t understand this:

Where do I put the code? Do I need to create a new file or something? Because I want it to stick with the theme, obviously.

Thanks for helping me out.


I added this in functions.php but nothing really happened to the customizer?

$wp_customize->add_control(
    'copyright_textbox',
    array(
        'label' => 'Copyright text',
        'section' => 'example_section_one',
        'type' => 'text',
    )
);

Solutions Collecting From Web of "Customizer options"

The easiest solution is to put it in your functions.php file in your theme’s directory. All the code in functions.php is automatically executed when the theme is active.

If the code in the file gets too much you can choose to divide it in smaller files and include those files in functions.php

EDIT

You should change your provided code snippet to the following

function wpse_228333_customize( $wp_customize ) {
    $wp_customize->add_control(
        'copyright_textbox',
        array(
            'label' => 'Copyright text',
            'section' => 'example_section_one', 
            'type' => 'text',
        )
    );
}
add_action( 'customize_register', 'wpse_228333_customize' );

EDIT 2

The problem with the code is that a control won’t show up if the attached section doesn’t exist. Also there is not a setting created that the control actually controls.

The code snippet below is a fully functional customizer section that adds a text field

function wpse_228333_customize( $wp_customize ) {

    /** First add a setting to be controlled / changed */
    $wp_customize->add_setting( 'wpse_228333_copyright_text' , array(
        'default'     => '',
    ) );

    /** Now add a section to put all your customizer controls in */
    $wp_customize->add_section( 'wpse_228333_section' , array(
        'title'      => __( 'My Custom Section!', 'text-domain' )
    ) );

    /** Now add a control to the previously made section to control the previously added setting */

    $wp_customize->add_control( 'wpse_228333_copyright_text_control', array(
        'label'      => __('Copyright text', 'themename'),
        'section'    => 'wpse_228333_section', // Corresponds to previously made section
        'settings'   => 'wpse_228333_copyright_text', // Corresponds to previously made setting
        'type'       => 'text'
    ));

}
add_action( 'customize_register', 'wpse_228333_customize' );