Adding a custom field to the site identity menu

It seems by default WordPress provides fields for site-title and tagline.

I understand how to add (for example) the option to chose a logo, adding add_theme_support( 'custom-logo' ); to the functions.php file. However, how do I add fields for ‘company name’ and ‘company division’ or for any text field that is not already part of the WordPress theme support?

2 s
2

You’ll have to add your own customizer controls to achieve that.

So for example, if you want to add Company Name, you can use this code:

function my_register_additional_customizer_settings( $wp_customize ) {
    $wp_customize->add_setting(
        'my_company_name',
        array(
            'default' => '',
            'type' => 'option', // you can also use 'theme_mod'
            'capability' => 'edit_theme_options'
        ),
    );

    $wp_customize->add_control( new WP_Customize_Control(
        $wp_customize,
        'my_company_name',
        array(
            'label'      => __( 'Company name', 'textdomain' ),
            'description' => __( 'Description for your field', 'textdomain' ),
            'settings'   => 'my_company_name',
            'priority'   => 10,
            'section'    => 'title_tagline',
            'type'       => 'text',
        )
    ) );
}
add_action( 'customize_register', 'my_register_additional_customizer_settings' );

PS. Here you can find more docs regarding this topic: Theme Customization API

Leave a Comment