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

By default it seems the editor inserts images using an absolute path.

We're developing a site in /staging/ and plan to move it later on. Is there a way to get relative paths on images to display properly in the editor? Maybe there's a function or snippet in the editor that resolves to the upload path or something?

So for example, my images in my home page are:

<img class="alignnone size-full wp-image-21" title="Authentic Chinese Food" src="wp-content/uploads/2011/04/panel_authentic.jpg" alt="Authentic Chinese Food" />

which display fine on the page itself, but not in the editor.

Thanks! John.

share|improve this question
This is fine for pages, but if you prepare posts that will later be fed to RSS readers they need the full URL to display the image. When I migrate a site from staging to live I just replace the URL in the post_content column of the wp_posts table. – Jan Fabry May 11 '11 at 10:32

I had a client ask for that and it took a little while to get it but its simple:

function change_mce_path_options( $init ) {
 $init['relative_urls'] = true;
 $init['document_base_url'] = get_bloginfo('url');
 return $init;
add_filter('tiny_mce_before_init', 'change_mce_path_options');
share|improve this answer
Not home_url? – kaiser May 11 '11 at 10:09
depends on your settings, but i just hard code the site url with trailing slash / – Bainternet May 11 '11 at 10:23
Where does this code go? In functions.php? – John Hunt May 15 '11 at 23:43
This didn't seem to work in functions.php when I used relative paths on my images in tinymce.. any ideas? – John Hunt May 15 '11 at 23:51
Whats your URL? And what code are you using? – Bainternet May 16 '11 at 7:30

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.