Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to remove scripts that are loaded in the footer in wordpress? I currently have the code that works for scripts but only for the one's that are added in the header via wp_enqueue_script. What it does is using preg_replace to match all the excluded scripts then replacing it with an empty string.

add_action('wp_head', array($this, 'plug_remove_scripts_start'), 0);
add_action('wp_footer', array($this, 'plug_remove_scripts_end'), 0);

public function plug_remove_scripts_start(){
  function remove_scripts($buffer){
    /*
   script for altering the buffer to remove the scripts
   */ 
    return $buffer;
  }
  ob_start("remove_scripts");
}

public function plug_remove_scripts_end(){
  ob_end_flush();
}

I already tried to change the wp_footer action hook into the following but it doesn't work:

  • loop start
  • plugins_loaded
  • shutdown

The script that I'm trying to target is right below the closing </footer> tag.

I've already considered using wp_dequeue_script under the wp_footer action. That would also work but I need to support those guys which aren't adding scripts and styles properly and simply pasting something like:

<script src="http://somesite.com/wp-content/js/somescript.js"></script>

Any ideas? If you know any plugin that already does this job (removing scripts that are loaded from a theme, plugin or widget) it would be great as well. Thanks in advance!

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.