Create a directory within the wordpress uploads folder
November 19, 2013 · Print This Article
When we developing a plugin or theme, it can be useful to be able to programmatically create a directory within the wordpress uploads folder.
Simply paste this code snippet on your functions.php file (or plugin file if you’re creating a plugin)
function my_upload_dir() {
$upload = wp_upload_dir();
$upload_dir = $upload['basedir'];
$upload_dir = $upload_dir . '/mypluginfiles';
if (! is_dir($upload_dir)) {
mkdir( $upload_dir, 0700 );
}
}
register_activation_hook( __FILE__, 'my_upload_dir' );
Comments
Got something to say?
You must be logged in to post a comment.