WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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 am creating a CSS generator in my WordPress theme and I want to be able to save custom skins with images as well. My problem is that I have a hierarchy like /skins/custom-skin/images for the uploaded images, but as you know the WordPress Media Uploader puts them in the uploads folder by default, sorted by date.

My question is, can I specify a path to save the image to every time a new image is uploaded?

share|improve this question
Where is the generator being utilized from? A custom admin page? Through a meta box on a post, page or custom post type, etc. – userabuser Oct 18 '12 at 7:33
up vote 2 down vote accepted


Dashboard -> Settings -> Media

You can uncheck the,

  ☑ Organize my uploads into month- and year-based folders

...and optionally change the path uploads (but this would effect all uploads of course).

Optionally you can hook onto the upload_dir filter and change the upload path for a given post_type, or for some other given scenario depending upon where and under what condition you are making these uploads.

add_filter( 'upload_dir', 'css_upload_dir' );

function css_upload_dir(){

    global $post;
    $post_id = $post->ID;
    $upload = wp_upload_dir();

    if( "post_type" == get_post_type($post_id) ){

        $custom_dir     = '/skins/custom-skin/images';
        $upload['path'] = $upload['basedir'] . $custom_dir;
        $upload['url']  = $upload['baseurl'] . $custom_dir;

        return $upload;

That should work, though I've not tested it, so I'm going off the top my head at the moment.

share|improve this answer
return $upload; after the if conditional, otherwise big errors. – aifrim Sep 15 '14 at 13:32
@aifrim edit the answer! ;) – userabuser Sep 16 '14 at 7:08
function() { .. if(...) {...} return $upload; } because: what happens if "post_type" == get_post_type($post_id) is FALSE? – aifrim Sep 16 '14 at 8:04

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.