title: Add wp_header depending on wp_content in Wordpress Plugin
body: <p>I am developing a Wordpress plugin to run a certain javascript function based on some parameters.</p>
  
  <p>The first step is to include the javascript file from my server. Easy:</p>
  
  <pre><code>add_action('wp_head', 'my_plugin_head');
  
  function my_plugin_head(){
  echo '&lt;script type="text/javascript" src="http://www.my-server.net/js/w.js" &gt;&lt;/script&gt;';
  }
  </code></pre>
  
  <p>The <em>second</em> step is to change certain text in the WordPress body to the javascript function...something like:</p>
  
  <pre><code> add_filter('the_content', 'plugin_text_replace');
   function plugin_text_replace($text){
   $text=preg_replace('blah', 'blah');
  
   return $text;
   //I Am still researching how to setup the preg_replace. 
   //It will look for something like plugin_call[1, 40, 60]
   //And Change it To jsFunction(1, 40, 60);
   //Bonus for anyone who can help me with that :)
   }
  </code></pre>
  
  <p>In any case, I realized that I want the my-server.net javascript included ONLY if needed (or in other words, only if the preg_replace found a match). This is problematic to me because I can't find anyway to add a script to the <code>&lt;head&gt;</code> tag without using an action on <code>wp_head</code>, which does not have any reference to the body of the text.</p>
  
  <p>How can I add a header ONLY if a certain preg_match is found?</p>