Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ControlledChaos
Forked from ajskelton/WP Customizer - URL
Created January 19, 2020 06:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ControlledChaos/e91b091899788ecae82e316393548f45 to your computer and use it in GitHub Desktop.
Save ControlledChaos/e91b091899788ecae82e316393548f45 to your computer and use it in GitHub Desktop.
Add a URL field to the WordPress Customizer.
$wp_customize->add_setting( 'themeslug_url_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'themeslug_sanitize_url',
) );
$wp_customize->add_control( 'themeslug_url_setting_id', array(
'type' => 'url',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom URL' ),
'description' => __( 'This is a custom url input.' ),
'input_attrs' => array(
'placeholder' => __( 'http://www.google.com' ),
),
) );
function themeslug_sanitize_url( $url ) {
return esc_url_raw( $url );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment