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">....'
.......
}
however doing so puts the template in the of every page/post. The idea is, I only want that block to be in the head in posts where that shortcode is present but I can't make the above work in the shortcode handler.
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 block in the same way?
Aucun commentaire:
Enregistrer un commentaire