jmccole83
9/26/2018 - 8:55 PM

CF7 | Stop form elements being wrapped in spans

CF7 auto-wraps elements in spans, add this snippet to functions.php to stop it. Required for MaterializeCSS to operate properly.

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