Last active
May 15, 2022 02:39
-
-
Save russo97/73f3f60eadc4bd2ae2f92438f37da081 to your computer and use it in GitHub Desktop.
WP replace HTML tags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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