title: WordPress: Move inline JS to be fired after deffered jQuery
body: <p>Trying to follow Google Page Insights suggestions, I've got the "JS render block" recommendation for and it is related to <code>jQuery</code> main file.</p>
  
  <p>My site use WordPress with some plugins. One of the plugins throw its JS inline. So when I move <code>jQuery</code> to load in the footer, or when I use "defer" mode to load it, I get <code>jQuery is not defined</code> once the inline code fired.</p>
  
  <p>I was trying to find a global solution to 'catch' all inline scripts and delay it after <code>jQuery</code> main file is executed at the end of the document.</p>
  
  <p>I wrote a solution that works great for me. It is very straight forward solution for my specific situation, but I failed to make this as a filter for <code>the_content</code> or widget output. I would like to make this a global solution, so I wouldn't need to worry about any JS firing somewhere.</p>
  
  <p>Any ideas how to make it work? Here my code so far, for this specific case, which runs through a shortcode:</p>
  
  <pre><code>/* Get shortcode HTML */ 
  $widget_shortcode = do_shortcode($shortcode);
  
  /* Take out all scripts into an array */
  $delayed_scripts = array();
  preg_match_all('#&lt;script(.*?)&lt;/script&gt;#is', $widget_shortcode, $match);
  foreach ($match as $val){
      $delayed_script = '&lt;script '.$val[0].'&lt;/script&gt;';
      array_push($delayed_scripts, $delayed_script);
  }
  
  /* Remove all scripts from HTML */
  $widget_shortcode = preg_replace('#&lt;script(.*?)&lt;/script&gt;#is', '', $widget_shortcode);
  
  /* Echo filtered HTML */
  echo $widget_shortcode;
  </code></pre>
  
  <p>And just before the closing <code>&lt;/body&gt;</code> tag:</p>
  
  <pre><code>foreach ($delayed_scripts as $script) {
      echo $delayed_script;
  }
  </code></pre>