Skip to content

Instantly share code, notes, and snippets.

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 webdevsuperfast/e042e9745e78a8521df183074ac386de to your computer and use it in GitHub Desktop.
Save webdevsuperfast/e042e9745e78a8521df183074ac386de to your computer and use it in GitHub Desktop.
WordPress: Contactfrom 7 - modifys contactform 7's default 'select' value of ---
// modifys contact form 7's default select value of --- to Please select...
function my_wpcf7_form_elements($html) {
$text = 'Please select...';
$html = str_replace('<option value="">---</option>', '<option value="">' . $text . '</option>', $html);
return $html;
}
add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
// Modify multiple selects
function my_wpcf7_form_elements($html) {
function ov3rfly_replace_include_blank($name, $text, &$html) {
$matches = false;
preg_match('/<select name="' . $name . '"[^>]*>(.*)<\/select>/iU', $html, $matches);
if ($matches) {
$select = str_replace('<option value="">---</option>', '<option value="">' . $text . '</option>', $matches[0]);
$html = preg_replace('/<select name="' . $name . '"[^>]*>(.*)<\/select>/iU', $select, $html);
}
add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
}
ov3rfly_replace_include_blank('menu-569', 'Choose language', $html);
ov3rfly_replace_include_blank('menu-614', 'Choose country', $html);
return $html;
}
// modifys contact form 7's default select value of --- to Please select...
function my_wpcf7_form_elements($html) {
$text = 'Please select...';
$html = str_replace('<option value="">---</option>', '<option value="">' . $text . '</option>', $html);
return $html;
}
add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment