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'm trying to use the Thickbox file upload dialogue with a custom field to allow the user to upload an mp3. What I want to do is to grab the URL of the uploaded mp3 and save it as postmeta (saving the data when I've got it isn't a problem, but getting what I need is!).

I've got the code to make this work with an image


var formfield = null;

$('#rps_upload_mp3').click(function() {
    formfield = $('#rps_mp3_url').attr('name');
    tb_show('', 'media-upload.php?type=image&TB_iframe=true');
    return false;

window.original_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html) {

    var fileurl;

    if( formfield = !null ) {

        fileurl = $('img', html).attr('src');

        formfield = null;

    } else {





Obviously the line that reads fileurl = $('img', html).attr('src'); will only get the src of an image, not an mp3, but I can't figure out where the script is grabbing the source of this image from and I don't know how to target the uploaded mp3.

Thanks in advance!

share|improve this question

The fileurl should look like this:

fileurl = $('a', html).attr('href');

It's a pretty simple fix. I would do some validation on this:

    //Do something awesome
    alert('The file you selected is not an MP3.');


share|improve this answer

File urls are returned as a single anchor tag as opposed to images which are returned as an anchor that contains an image tag.

So to reference a file url in wordpress file uploader, you use:


Then you can use Brian Fegter's response to check the file type.

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.