一种常见的方法是在tmpl-attachment-details
模板:
// See wp_print_media_templates() in "wp-includes/media-template.php"
function wpse157297_print_media_templates() {
$my_link = \'<a class="my_link-attachment" href="my_link.php?url={{ data.url }}" target="_blank">\' . __( \'My Link\' ) . \'</a>\';
$nonimage = \'<# if ( "image" !== data.type && ! data.uploading ) { #>\' . $my_link . \'<# } #>\';
$image = $my_link;
?>
<script>
(function ($) {
var tmpl_attachment_details = $(\'#tmpl-attachment-details\'), html = tmpl_attachment_details.html();
tmpl_attachment_details.html(
html.replace( /<div class="uploaded">[^<]*<\\/div>/, \'$&<?php echo $nonimage; ?>\' ).replace( \'<a class="edit-attachment"\', \'<?php echo $image; ?>$&\' )
);
})(jQuery);
</script>
<?php
}
add_action( \'print_media_templates\', \'wpse157297_print_media_templates\', 11 );
除了
{{ data.url }}
, 有
{{ data.id }}
,
{{ data.filename }}
etc-参见
wp_prepare_attachment_for_js()
在“wp includes/media.php”中