Title: Front-end upload button
Last modified: August 30, 2016

---

# Front-end upload button

 *  [snipen](https://wordpress.org/support/users/snipen/)
 * (@snipen)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/front-end-upload-button/)
 * I’m reaching out for help after days of searching; I need users to be able to
   upload an image to be attached to a custom post. I find many hacks and descriptions
   about how to customize on admin page but none for the front-end. I was hoping
   to be able to tweak this code, but I think i get stuck on the wp.media bit that
   only runs in the admin pages.
    ` function open_media_window() { if (this.window
   === undefined) { this.window = wp.media({ title: ‘Insert a media’, library: {
   type: ‘image’}, multiple: false, button: {text: ‘Insert’} });
 *  var self = this; // Needed to retrieve our variable in the anonymous function
   below
    this.window.on(‘select’, function() { var first = self.window.state().
   get(‘selection’).first().toJSON(); wp.media.editor.insert(‘[myshortcode id=”‘
   + first.id + ‘”]’); }); }
 *  this.window.open();
    return false; }
 * Source: [http://www.sitepoint.com/adding-a-media-button-to-the-content-editor/](http://www.sitepoint.com/adding-a-media-button-to-the-content-editor/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [snipen](https://wordpress.org/support/users/snipen/)
 * (@snipen)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/front-end-upload-button/#post-6711273)
 * Source: [](http://www.sitepoint.com/adding-a-media-button-to-the-content-editor/)

Viewing 1 replies (of 1 total)

The topic ‘Front-end upload button’ is closed to new replies.

## Tags

 * [button](https://wordpress.org/support/topic-tag/button/)
 * [front-end](https://wordpress.org/support/topic-tag/front-end/)
 * [upload](https://wordpress.org/support/topic-tag/upload/)

 * 1 reply
 * 1 participant
 * Last reply from: [snipen](https://wordpress.org/support/users/snipen/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/front-end-upload-button/#post-6711273)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
