Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there a way to change the upload directory's location and format from YYYY/MM (/wp-content/uploads/2013/06) to MMYY (/news/0613)?
I've searched everywhere and could not find an answer - in fact, the latest version of WP even removed the ability to change where to even put the upload directory. Thank you! :)

share|improve this question
add comment

1 Answer

/** Force wp_upload_dir() to use time-based paths. */
add_filter( 'pre_option_uploads_use_yearmonth_folders', '__return_true' );

/**
 * Use the date format MMYY instead of YYYY/MM in the uploads path.
 *
 * @param  array $dir
 * @return array
 */
function wpse_104005_upload_dir( $dir ) {
    if ( preg_match( '!/([0-9]{4})/([0-9]{2})!', $dir['subdir'] ) ) { // Check we do indeed have a date-based subdir
        $dir['subdir'] = '/' .  substr( $dir['subdir'], 6, 2 ) . substr( $dir['subdir'], 3, 2 );
        $dir['path'] = $dir['basedir'] . $dir['subdir'];
        $dir['url'] = $dir['baseurl'] . $dir['subdir'];
    }

    return $dir;
}

add_filter( 'upload_dir', 'wpse_104005_upload_dir', 100 );

It's a little frustrating that the filter upload_dir doesn't pass along the $time variable too, hence resorting to regex on the subdir.

Update: In regards to your problem, load wp-admin/options.php in the browser, then make sure the following values are:

    upload_path: news
upload_url_path: http://domain.com/news

If that still fails, try using the full path in upload_path (usually something like /user/public_html/news, use phpinfo() if not sure).

share|improve this answer
    
Thanks so much! When I try to upload though I get this error: "Unable to create directory news/0613. Is its parent directory writable by the server?" I've tried the whole 777 thing, changing the directory, adding a / before it, using the server path, the full path, etc. Any ideas? –  user1445975 Jun 24 '13 at 17:49
    
Have you made sure that news exists & is 777? –  TheDeadMedic Jun 24 '13 at 22:34
    
Yep, it exists and it's set to 777. –  user1445975 Jun 25 '13 at 0:11
    
what do you mean "changing the directory"? –  TheDeadMedic Jun 25 '13 at 0:25
    
Making a new folder, such as "news2," and making it 777. –  user1445975 Jun 25 '13 at 7:46
show 2 more comments

Your Answer

 
discard

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.