Skip to content

Instantly share code, notes, and snippets.

@mkormendy
Last active June 13, 2016 21:09
Show Gist options
  • Save mkormendy/bd033c4e0ec7941e592aca31b77e5c16 to your computer and use it in GitHub Desktop.
Save mkormendy/bd033c4e0ec7941e592aca31b77e5c16 to your computer and use it in GitHub Desktop.
Pushing code manually with javascript into the wp media template...
add_action('print_media_templates', function() {
?>
<script>
var el = document.getElementById('tmpl-attachment');
var pos = el.outerHTML.indexOf('<# } else if ( \'image\' === data.type && data.sizes ) { #>');
var text = '<# } else if ( \'svg+xml\' === data.subtype ) { #>\n' +
'<div class="centered">\n' +
'<img src="{{ data.url }}" class="thumbnail" draggable="false" />\n' +
'</div>\n' +
'<div class="filename">' +
'<div>{{ data.filename }}</div>' +
'</div>';
el.outerHTML = [el.outerHTML.slice(0, pos), text, el.outerHTML.slice(pos)].join('');
</script>
<?php
}, 42);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment