Advertisement
Guest User

Remove Stuff From Footer

a guest
Sep 19th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. function mu_footer_filter(){
  2.     function my_start_footer_ob() {
  3.         ob_start("my_end_footer_ob_callback");
  4.     }
  5.     add_action('wp_footer', 'my_start_footer_ob');
  6.  
  7.     function my_end_footer_ob() {
  8.         ob_end_flush();
  9.     }
  10.     add_action('wp_footer', 'my_end_footer_ob', 1000);
  11.  
  12.     function my_end_footer_ob_callback($buffer) {
  13.         /** The Following Preg replace / Buffer Does Not Work **/
  14.         //$buffer = preg_replace('/<div id=\"test\">.*<\/div>/', 'asdf', $buffer);
  15.         //return $buffer;
  16.        
  17.         /** The HTML Portion does not work **/
  18.         $doc = new DOMDocument;
  19.         $doc->loadHTML($buffer);
  20.  
  21.         $docElem = $doc->getElementById("test");
  22.  
  23.         if($docElem !== NULL) // if it exists
  24.             $docElem->parentNode->removeChild($docElem);
  25.  
  26.         return $doc->getElementsByTagName('body')->firstChild->nodeValue;
  27.     }
  28. }
  29. add_action('muplugins_loaded', 'mu_footer_filter');
  30.  
  31. function test(){
  32.     $test = '<div id="test">test</div>';
  33.     // $test = preg_replace('/<div id=\"test\">.*<\/div>/', '', $test); // This Preg Replace is functional.
  34.     echo $test;
  35. }
  36. add_action('wp_footer', 'test');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement