So I have run into a little glitch. i have a custom path for uploads and it works. the files get saved to the right place, etc. The problem I have is the 'widget box' in the admin section. immediately after uploading and setting the uploaded image as the featured image, it show up in the preview, instead of www.blog.com/blog/uploads/POST_ID/image_name.png it is showing

www.blog.com/blog/uploads/image_name.png The path is broken. Again I am new to WP... is there a filter for the admin 'widget box's?

The path I get back is: <img width="266" height="145" src="http://mysite.com/blog/wp-content/uploads/image-350x192.png" class="attachment-266x266" alt="the title" title="the title">

But where the image resides is: <img width="266" height="145" src="http://mysite.com/blog/wp-content/uploads/<POST_ID>/image-350x192.png" class="attachment-266x266" alt="the title" title="the title">

I cant add an image because of my rep so far... it appears in the same column as tags and categories in the admin area. It is a custom widget for this theme.


    function media_upload_dir($upload) {
        return $upload;
$id = $_REQUEST['post_id'];
        if (isset($_REQUEST['post_id'])) {
            $upload['path']    = "/path/www/blog/wp-content/uploads/" . $id;
            $upload['url']     = "http://site.com/blog/wp-content/uploads/" . $id;
            $upload['basedir'] = "/path/www/blog/wp-content/uploads/" . $id;
            $upload['baseurl'] = "http://site.com/blog/wp-content/uploads/" . $id;
            if (!file_exists("/path/www/blog/wp-content/uploads/" . $id)) {
                mkdir("/path/www/blog/wp-content/uploads/" . $id, 0777);
        return $upload;
    add_filter('upload_dir', 'media_upload_dir');


  • What do you refer as the "widgets box"? Is it the Featured Image box? A screenshot could be useful. Also, is this path being printed or you see it when inspecting the html code?
    – brasofilo
    May 28 '12 at 16:22
  • yes the featured image! May 30 '12 at 14:04
  • But you can post a link to some screenshots somewhere else... What about the path, how are you checking it?
    – brasofilo
    May 30 '12 at 14:49
  • i added the path above. using firebug May 30 '12 at 14:52
  • How are you setting the custom upload paths? Your custom widget may need to be adapted accordingly.
    – MathSmath
    May 30 '12 at 18:15

This is not a answer, is an extended comment with the link to the solution.

First, while testing, one of my test sites wasn't showing the Featured Image uploaded to the folder /wp-content/uploads/POST_ID/image_name.jpg. Same problem as the OP.

But, it was not displaying any path to the image. And the bug was that the installation where I was testing is full of hacks (my main WPSE testing base). As soon as I went to a stable installation everything worked.

So, if your problem persist, do a full troubleshooting:

Also, Robert, when asking a question please provide all the elements that a person who is willing to help will need to understand and effectively answer it.

Side notes to your code:

Best regards and good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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