Title: Adding  block to header
Last modified: August 22, 2016

---

# Adding block to header

 *  Resolved [ericrosete](https://wordpress.org/support/users/ecdoesit/)
 * (@ecdoesit)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/adding-block-to-header/)
 * I’m building a plugin that uses a shortcode to display a map and list of locations.
   Part of displaying that list of locations requires a handlebars.js template.
 * That template exists as a <script> block in the <head>. It works fine when I 
   use
 *     ```
       add_action('wp_head', 'template_locations');
   
       function template_locations() {
       echo "<script id="locations" type="text/x-handlebars-template">...."
       }
       ```
   
 * but not when it is called in the shortcode handler. The idea is, I only want 
   that block to be in the head in posts where that shortcode is present.
 * I’ve been able to register other scripts in the plugin and then having them enqueue
   as part of the shortcode handler so that they are only loaded when a shortcode
   is present. My question is, how would I register/enqueue a <script> block in 
   the same way?

Viewing 1 replies (of 1 total)

 *  Thread Starter [ericrosete](https://wordpress.org/support/users/ecdoesit/)
 * (@ecdoesit)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/adding-block-to-header/#post-5936812)
 * I ended up using [has_shortcode](https://codex.wordpress.org/Function_Reference/has_shortcode),
   specifically the last example.

Viewing 1 replies (of 1 total)

The topic ‘Adding block to header’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [ericrosete](https://wordpress.org/support/users/ecdoesit/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/adding-block-to-header/#post-5936812)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
