Skip to content

Instantly share code, notes, and snippets.

@russo97
Last active May 15, 2022 02:39
Show Gist options
  • Select an option

  • Save russo97/73f3f60eadc4bd2ae2f92438f37da081 to your computer and use it in GitHub Desktop.

Select an option

Save russo97/73f3f60eadc4bd2ae2f92438f37da081 to your computer and use it in GitHub Desktop.
WP replace HTML tags
<?php
add_filter('wpcf7_form_elements', function( $content ) {
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$xpath = new DomXPath($dom);
$spans = $xpath->query("//span[contains(@class, 'wpcf7-form-control-wrap')]" );
foreach ( $spans as $span ) :
$children = $span->firstChild;
$span->parentNode->replaceChild( $children, $span );
endforeach;
return $dom->saveHTML();
});
add_filter('wpcf7_form_elements', function ($content) {
$content = str_replace("type=\"url\"", "inputmode=\"url\" type=\"url\"", $content);
$content = str_replace("type=\"tel\"", "inputmode=\"numeric\" type=\"tel\" autocomplete=\"tel\"", $content);
$content = str_replace("type=\"email\"", "inputmode=\"email\" type=\"email\" autocomplete=\"email\"", $content);
return $content;
});
add_filter('wpcf7_autop_or_not', '__return_false');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment