Use the first_as_label
option instead of include_blank
.
You can add filter hook for changing default text ” —Please choose an option—” .
$html = str_replace(‘—Please choose an option—’, $text, $html);
function my_wpcf7_form_elements($html) {
//wp_send_json($html );
$text = 'Select Option';
$html = str_replace('—Please choose an option—', $text, $html);
return $html;
}
add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
]]>
include_blank
with first_as_label
works great, thanks!
]]>
include_blank
with first_as_label
(function ($) {
'use strict';
$(document).ready(function () {
var $select = $('.wpcf7-select');
$select.each(function(e){
var first_option = $(this).find('option').first();
if(first_option.attr('value') == ''){
first_option.attr('disabled', true);
}
})
});
})(jQuery)
]]>
function wpcf7_select_placeholder_update($html) {
$text = 'How did you hear about us?';
$html = str_replace('<option value="">—Please choose an option—</option>', '<option value="">' . $text . '</option>', $html);
return $html;
}
add_filter('wpcf7_form_elements', 'wpcf7_select_placeholder_update');
Try this and also as mentioned above use (&@8212 ; ) instead of –
]]><script>
$(function() {
$('.wpcf7-select option:first-child[value=""]').prop('disabled', true);
});
</script>
]]>
When posting a comment, editor script forcefully converts &# 8212; into em dash, but with those dashes code by mandipluitel and by MH Sohag does not work, being otherwise right. Since in the code generated by Contact form 7 text to replace looks like: “&# 8212;Please choose an option&# 8212;”, not with dashes.
Note: I put &# + blank space + 8212 to avoid conversion to em dash, so that blank space should be remove in the actual code.
]]>