Skip to content

Instantly share code, notes, and snippets.

@w3guy
Last active September 28, 2019 19:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w3guy/084e7f983c4483d6444a28447085b665 to your computer and use it in GitHub Desktop.
Save w3guy/084e7f983c4483d6444a28447085b665 to your computer and use it in GitHub Desktop.
WordPress customizer range control with indicator for selected value. http://w3guy.com/wordpress-customizer-range-control-selected-indicator/
(function ($) {
$(document).ready(function ($) {
$('input[data-input-type]').on('input change', function () {
var val = $(this).val();
$(this).prev('.cs-range-value').html(val);
$(this).val(val);
});
})
})(jQuery);
<?php
class WP_Customize_Range_Control extends WP_Customize_Control
{
public $type = 'custom_range';
public function enqueue()
{
wp_enqueue_script(
'cs-range-control',
'path/to/range-control.js',
array('jquery'),
false,
true
);
}
public function render_content()
{
?>
<label>
<?php if ( ! empty( $this->label )) : ?>
<span class="customize-control-title"><?php echo esc_html($this->label); ?></span>
<?php endif; ?>
<div class="cs-range-value"><?php echo esc_attr($this->value()); ?></div>
<input data-input-type="range" type="range" <?php $this->input_attrs(); ?> value="<?php echo esc_attr($this->value()); ?>" <?php $this->link(); ?> />
<?php if ( ! empty( $this->description )) : ?>
<span class="description customize-control-description"><?php echo $this->description; ?></span>
<?php endif; ?>
</label>
<?php
}
}
@BicanMarianValeriu
Copy link

invalid value error on wp ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment