14

As the recent changes in WordPress 3.5 removed the "full URL path to files" option from media library I am wondering how to set this option to a custom path now?

I need to set my "full URL path to files" for my media files to a custom subdomain. Can you guys help me out with finding a solution for this problem?

Regards, faxxim

16

The option name is upload_url_path, and you can still filter it:

add_filter( 'pre_option_upload_url_path', 'wpse_77960_upload_url' );

function wpse_77960_upload_url()
{
    return 'http://subdomain.example.com/files';
}
  • 1
    remove trailing slash because you will have double slashes in the url, like 'http://subdomain.example.com/files//path/to/image.jpg' – Eugene Manuilov Jan 2 '13 at 10:55
  • OK, good to know its that easy! Thank you very much! – faxxim Jan 2 '13 at 10:58
  • 1
    @toscho I know that it will work, but it is not feng shui to have double slashes :) – Eugene Manuilov Jan 2 '13 at 11:07
  • 1
    @EugeneManuilov That’s why I remove those per .htaccess. – fuxia Jan 2 '13 at 11:10
  • 2
    @bueltge UPLOADS is a file path, upload_url is an URL. Two different URLs can point to the same local path, and there is no way to determine the correct URL for a given path. So both are two different things. – fuxia Jan 28 '13 at 16:46
7

Thank you @Toscho for providing me with the name of the option. Here's another way to change it, by placing this in your functions.php file:

update_option('upload_url_path', '/wp-content/uploads');

This will make WordPress embed images like src="/wp-content/uploads/file.jpg" instead of src="http://domain.com/wp-content/uploads/file.jpg"

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