/** 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'] = "https://wordpress.stackexchange.com/" . 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).