title: Use WordPress shortcode to add <meta> tags
body: <p>I'm writing a simple WordPress plugin that uses shortcode. I want the page that contains the shortcode to have specific <code>&lt;meta&gt;</code> tags. Is this possible? And if so, is there an elegant way to do it?</p>
  
  <p>I know that I can add <code>&lt;meta&gt;</code> tags with the <code>wp_head</code> hook, but I want the meta tag content to match a string produced by the plugin. I could move all the code into the header, but then I'm not sure how to reference it later from the shortcode. In other words, when I declare a variable in the <code>&lt;head&gt;</code> with a filter, it's not available to the class methods that I'm calling with the shortcode.</p>
  
  <p>Any ideas?</p>
  
  <p>UPDATE: </p>
  
  <p>A nice solution was proposed in which the handler function for the shortcode adds the action to the wp_head hook:</p>
  
  <pre><code>add_shortcode('fakeshortcode', 'fakeshortcode_handler');
  function fakeshortcode_handler() {
  
      function add_meta_tags() {
          //echo stuff here that will go in the head
      }
      add_action('wp_head', 'add_meta_tags');
  }
  </code></pre>
  
  <p>This is swell, but the problem is that wp_head happens BEFORE the shortcode gets parsed and adds the action (so nothing gets added to the head with the code above ALONE). To make it work, I borrowed the solution in <a href="https://wordpress.stackexchange.com/questions/17513/append-stylesheet-via-shortcode">this post</a>. It's basically a function that "looks ahead" into the post and sees if there is any shortcode coming. If it is, then IT adds the <code>add_action('wp_head'...</code>. </p>
  
  <p>EDIT:
  I removed my follow-up question about how to pass the variable.
  It's a new question <a href="https://stackoverflow.com/questions/9573344/how-can-i-pass-a-variable-wordpress-shortcode">here</a>.</p>