WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Sometimes it's nice to have admin on a different host (admin.mysite.com) then the actual site (www.mysite.com).

If admin.mysite.com is not publicly accessible, then images attached to posts on admin.mysite.com will not be accessible on www.mysite.com since the url to the attached image is absolute and contains the domain (admin.mysite.com).

Is there any way to fix this? The nicest way would be if the url to an attached media would be relative and not absolute.

share|improve this question

you can configure the tinymce to use relative paths for images using the tiny_mce_before_init like this:

function tinymce_relative_path( $init ) {
 $init['relative_urls'] = true;
 $init['document_base_url'] = 'http://www.mysite.com';
 return $init;
add_filter('tiny_mce_before_init', 'tinymce_relative_path');
share|improve this answer
This doesn't seeem to work for me. The function 'tinymce_relative_path' is being called (from functions.php) but tinymce still doesn't save relative urls. I'm running WordPress 3.1.4. – D. Wroblewski Aug 7 '11 at 15:58
up vote 1 down vote accepted

I found another way of doing this. I added the following to functions.php:

function yoursite_get_relative_attachment_path($path)
    $paths = (object)parse_url($path);
    return $paths->path;

function yoursite_wp_handle_upload($info)
    $info['url'] = yoursite_get_relative_attachment_path($info['url']);
    return $info;
add_filter('wp_handle_upload', 'yoursite_wp_handle_upload');

function yoursite_wp_get_attachment_url($url)
    return yoursite_get_relative_attachment_path($url);
add_filter('wp_get_attachment_url', 'yoursite_wp_get_attachment_url');

This way wordpress stores the relative URL in the db.

For more detailed instructions see the blog where I learned about this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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