Suporte » Desenvolvendo com WordPress » Replace nos campos Select do Contact Form 7

  • Caros amigos,

    Achei na Web o código abaixo que me é muito útil, ele dá um replace nos campos Select do Contact Form 7 colocando um valor inicial como se fosse um placeholder.

    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('sexo', 'Sexo*', $html);
        ov3rfly_replace_include_blank('civil', 'Estado Civil*', $html);
        ov3rfly_replace_include_blank('escolaridade', 'Escolaridade*', $html);
        return $html;
    }
    add_filter('wpcf7_form_elements', 'my_wpcf7_form_elements');

    O problema é que quando vou colcoar um formulário no Widget apresenta o erro:

    Fatal error: Cannot redeclare ov3rfly_replace_include_blank() (previously declared in /home/storage/7/70/5b/meusite/public_html/wp-content/themes/meutema/functions.php:65) in /home/storage/7/70/5b/meusite/public_html/wp-content/themes/meutema/functions.php on line 65

    A linha 65 é esta:
    function ov3rfly_replace_include_blank($name, $text, &$html) {

    Alguém pode ajudar resolver isso? Tipo, não execute se for se estiver dentro de um Widget.

    Obrigado pela atenção de todos

  • O tópico ‘Replace nos campos Select do Contact Form 7’ está fechado para novas respostas.