How can I solve the following issue with the code attached? Seems that somehow WordPress (or some kind of plugin) is calling the function twice.
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);
}
}
ov3rfly_replace_include_blank('countrylist', 'España', $html);
return $html;
}
add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');
Fatal error: Cannot redeclare ov3rfly_replace_include_blank() (previously declared in /Applications/XAMPP/xamppfiles/htdocs/w/wp-content/themes/bulwark_child/functions.php:21) in /Applications/XAMPP/xamppfiles/htdocs/w/wp-content/themes/bulwark_child/functions.php on line 21
Dont nest the functions – your current code declares the inner function every time the outer function is called, thereby causing the error the second time:
Check this file for re declare function as error message suggested
rename one function and see whether it working or not
Write a separate function,multiple function calling in nested function: