Customizer – How to get theme mod range value?

I was able to get the value of the range slider to save and display by changing the sanitize_callback value to a custom function that returns an integer value:

    $wp_customize->add_section( 'range', array (
        'title'    => __( 'Range', 'textdomain' ),
        'priority' => 45,
    ) );

    $wp_customize->add_setting( 'range_field_id1', array(
        'default' => '',
        'type' => 'theme_mod',
        'capability' => 'edit_theme_options',
        'transport' => '',
        'sanitize_callback' => 'wpse_intval',
    ) );

    $wp_customize->add_control( 'range_field_id1', array(
        'type' => 'range',
        'priority' => 10,
        'section' => 'range',
        'label' => __( 'Range Field', 'textdomain' ),
        'description' => '',
    'input_attrs' => array(
            'min' => 1,
            'max' => 100,
            'step' => 1,
            'class' => 'example-class',
            'style' => 'color: #ff0022',
            ),
    ));

I defined the simple wpse_intval() function outside of the customizer class:

function wpse_intval( $value ) {
    return (int) $value;
}

I used the same code posted in the original question to display the saved value:

$content_mod = get_theme_mod('range_field_id1');
var_dump( $content_mod );

At this point, I’m not sure why this is happening, because intval() seems like it should work.

Mini note: the Customizer Dev Tools plugin is a handy tool for troubleshooting.

tech