Sanitize Float Number in WorpPress Customizer

function theme_sanitize_float( $input ) {
    return filter_var($input,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
}
$wp_customize->add_setting( 'post_type_number', array(
    'sanitize_callback' => 'theme_sanitize_float',
    'default'     => 20,
) );
$wp_customize->add_control( new WP_Customize_Control( $wp_customize,'post_type_number', array(
	'type' => 'number',
	'priority' => 42,
	'section' => 'post_type',
	'label'       => esc_attr__( 'Number to be shown:', 'theme' ),'input_attrs' => array(
	'min'  => 1,
	'max'  => 500,
	'step' => 0.1,
),
) ) );

Leave a Reply