I'm using the Media Uploader to select a file url for a custom post type. I'm expecting the html parameter for send_to_editor to be a string html tag that includes the file url as the src or href. This works for most file types but not for pdf files. For pdfs, the parameter is simply the name of the file without a tag. Any Ideas?

var formfield;

function extractUri(text) {
    var uri_pattern = /\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/ig;

    return text.match(uri_pattern)[0];

// Open upload window
$('#upload-file-button').click(function() {
    formfield = $('#upload_file').attr('name');
    tb_show( '','media-upload.php?type=file&TB_iframe=true' );
    return false;

window.original_send_to_editor = window.send_to_editor;

//html param for img -> <img src="FILE_URL" >
//html param for pdf -> "FILE_NAME"
window.send_to_editor = function(html) {
     var uri = extractUri(html);
     if (formfield) {
     } else {

1 Answer 1


Found a filter that works for this situation

function media_to_editor($html, $send_id, $attachment ){
   $attachment_url = wp_get_attachment_url($send_id);
   return $attachment_url;

add_filter('media_send_to_editor', 'media_to_editor', 10, 2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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