Answer the question
In order to leave comments, you need to log in
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;
};
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question