Infinite loop to delete a DOM element
-
Hi, I have to delete two elements in a page DOM, only for non logged users, and I have to do it in PHP for security issues. The following code would seem to work, but causes an infinite loop in the page load. I’ve addes this code at the end of footer.php of wordpress theme folder, before </body> and </html>.
Thanks for help!<?php if ( !is_user_logged_in() ) { $dom = new DOMDocument(); $dom->load("https://www.mysite.it/product/product1/"); $selector = new DOMXPath($dom); foreach($selector->query('//div[contains(attribute::class, "my-class1")]') as $e ) { $e->parentNode->removeChild($e); } $dom->saveHTML(); $dom = new DOMDocument(); $dom->load("https://www.mysite.it/product/product1/"); $selector = new DOMXPath($dom); foreach($selector->query('//a[contains(attribute::class, "my-class2")]') as $e ) { $e->parentNode->removeChild($e); } $dom->saveHTML(); } ?>
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Infinite loop to delete a DOM element’ is closed to new replies.