We have a CPT which is used to manage various assets including image, pdf, CAD and other files.

Our client would like to keep these asset files seperate from their other media files and does NOT want them to appear in the WP media panel.

We have found this useful snippet which allows us to upload to a custom folder inside the WP uploads folder:

function my_upload_dir($upload) {
    $upload['subdir']   = '/assets';
    $upload['path']     = $upload['basedir'] . $upload['subdir'];
    $upload['url']      = $upload['baseurl'] . $upload['subdir'];
    return $upload;

add_filter('upload_dir', 'my_upload_dir');
$uploaded_file = wp_handle_upload($_FILES['xxxx'], $upload_overrides);
remove_filter('upload_dir', 'my_upload_dir');

How could we adapt this properly to upload images for this CPT to a custom 'assets' folder, for example: wp-content/assets ?

Thanks in advance for any help!

1 Answer 1


This is impossible to do (or at the very least not easy). The way the uploading process works is that first you upload a file to the media library, and only after the file is in the media library you may associate it with a post.

The usage of the media library is mandatory if you want to use the media workflow, and you are more likely to break something that might not be immediately obvious if you try to avoid it.

If your client do not want to use the media library then he should just upload the files in FTP and insert manually the links. (of course this leads to maintenance nightmare in the long run, which is why wordpress stopped doing things like that about 20 releases ago).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.