Skip to content

Instantly share code, notes, and snippets.

@ajskelton
Last active September 1, 2019 04:31
Show Gist options
  • Save ajskelton/8d7122dfacdb33be83dba476e5dd10ae to your computer and use it in GitHub Desktop.
Save ajskelton/8d7122dfacdb33be83dba476e5dd10ae to your computer and use it in GitHub Desktop.
Add a Email field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_email_setting_id', array(
'capability' => 'edit_theme_options',
'default' => '',
'sanitize_callback' => 'themeslug_sanitize_email',
) );
$wp_customize->add_control( 'themeslug_email_setting_id', array(
'type' => 'email',
'section' => 'custom_section', // Required, core or custom.
'label' => __( 'Custom Email' ),
'description' => __( 'This is a custom email input.' ),
'input_attrs' => array(
'placeholder' => __( 'email@domain.com' ),
),
) );
function themeslug_sanitize_email( $email, $setting ) {
return ( is_email($email) ? $email : $setting->default );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment