D
D
Dmitry Klimantovich2021-11-14 19:29:26
WordPress
Dmitry Klimantovich, 2021-11-14 19:29:26

How can I remove the wrapper only in the forms I need?

Using this entry, you can remove the wrapper in all form elements

add_filter('wpcf7_form_elements', 'wpcf7_remove_span_wrapper');
    function wpcf7_remove_span_wrapper($content) {
        $content = preg_replace('/<(span).*?class="\s*(?:.*\s)?wpcf7-form-control-wrap(?:\s[^"]+)?\s*"[^\>]*>(.*)<\/\1>/i', '\2', $content);

        $content = str_replace('<br />', '', $content);

        return $content;
    };

But how to remove them only from forms, for example, under a certain id?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WP Panda, 2021-11-14
@dikey58

something like this
Add to the elements of those forms where you want to do this with your class, for example target-class, and then check for its presence and remove the wrapper

add_filter( 'wpcf7_form_elements', 'wpcf7_remove_span_wrapper' );
  function wpcf7_remove_span_wrapper( $content ) {
    $str_pos = strpos( $content, 'target-class' );
    if ( $str_pos !== false ) {
      $content = preg_replace( '/<(span).*?class="\s*(?:.*\s)?wpcf7-form-control-wrap(?:\s[^"]+)?\s*"[^\>]*>(.*)<\/\1>/i', '\2', $content );

      $content = str_replace( '<br />', '', $content );
    }

    return $content;
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question