WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've noticed that since WP 3.5 that we now have the Backbone.js and Underscore.js libraries included. The new Media Modal uses Underscore templates and I was wondering how would I be able to insert them, especially in the admin side of things.Is there a correct way to insert these?

share|improve this question
Please search the site for questions related to how to enqueue scripts. – Chip Bennett Feb 25 '13 at 15:05
possible duplicate of Where is the right place to register/enqueue scripts & styles – Chip Bennett Feb 25 '13 at 15:05
@ChipBennett this question is not about register/enqueue scripts, it is about using underscore templates in new Media popup – Eugene Manuilov Feb 25 '13 at 15:08
Technically you're both right. My fault for posting a question while half asleep. – Manny Fleurmond Feb 25 '13 at 15:14
Can you load an Underscore template from an external file via a script tag? – Manny Fleurmond Feb 25 '13 at 15:27
up vote 6 down vote accepted

Your plugin index file:

add_action( 'print_media_templates', 'wpse8170_admin_footer' );
function wpse8170_admin_footer() {

    require 'templates.php';

Your templates.php:

<script id="tmpl-mytemplate" type="text/html">
    <h1>Hello {{data.name}}!</h1>

Your media js file:

wp.media.view.MyView = wp.media.View.extend({
    template: wp.media.template('mytemplate'),

    render: function() {
        this.$el.html(this.template({name: 'world'}));
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.