title: global post variable not working in wordpress plugin
body: <p>I understand that the Wordpress global <code>$post</code> may not work until a certain point because it hasnt been loaded, but Im wondering is there a workaround for this.</p>
  
  <p>Basically Im building a plugin specifically for a client. At the moment the variable is showing nothing.</p>
  
  <p>This code is in a plugin in the plugins folder.</p>
  
  <p>Im looking to make sure it only loads javascript (Ive left out that bit) when on specific pages (selected by the user), at the moment its loading on all pages.</p>
  
  <p>My other option is to do it all on a php template, but to be honest I wanted to write it as a plugin with a view to customizing it for more generic use in the future, plus I have little experience with plugins so Im trying to improve that side of things also.</p>
  
  <pre><code>function include_js() {
    global $post;
    print_r($post);
  
    if(is_object($post) &amp;&amp; $post-&gt;ID == 14 ){ 
     // do stuff
     wp_enqueue_script('include-map',  plugin_dir_url( __FILE__ ) . 'map.js');
    }
  }
  
  add_action( 'init', 'include_js' );
  </code></pre>
  
  <p>EDIT: I realised my main issue is that I want to include the javascript and because of that I need <code>wp_enqueue_script</code> , but I can only seem to get that work if you use the <code>init</code> action, which happens before the loop.</p>