Forked from landru247/WordPress: Contactfrom 7 - modifys contactform 7's default 'select' value
Last active
July 6, 2018 17:57
-
-
Save barbwiredmedia/6a9832981b2809037771 to your computer and use it in GitHub Desktop.
cf7, select, form. To target a particular form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 - Target each one specifically | |
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; | |
} | |
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