Support » Requests and Feedback » Relative URL for local images request

  • Can we adjust the image insert function to only insert a relative url instead of a full path to an image file?

    <img src="/wp-content/uploads/filename.jpg" />


    <img src="" />

    This would make it much easier in the database if/when we change a blog directory, go from working on local machine to live server, etc..etc..

    Thanks to all the developers who make wordpress happen, and I do hope this is something you will consider.


Viewing 7 replies - 1 through 7 (of 7 total)
  • any news on this? i would really like this as well

    Even <img src="/wp-content/uploads/filename.jpg" /> is still absolute with respect to the domain.

    Better would be to support relative URLs like <img src="wp-content/uploads/filename.jpg" />. That way a site can be developed in a folder and moved up to the root (or to another folder) when deployed.

    This would require either an output filter that modifies these relative URLs depending upon the current page path, or the use of the “base” meta-tag to tell the browser to treat all relative paths wrt the site root.

    I’m going through this myself at the moment, and am use to just being able to move a whole CMS, knowing that all links are relative, so this came as a surprise to me.

    — Jason

    I agree. I’ve been waiting for this feature addition for a while. I think it should be built into WordPress and not a plugin/filter.

    Just install some php execution plugin to allow you to insert php codes on your posts (I recommend Then simply write your posts using relative paths, such as:

    <img border=”0″ src=”=”<?php echo $ROOT; ?>/zzzz/xxxx/mypic.jpg” width=”100″ height=”100″>


    <?php echo ‘<img border=”0″ src=”‘ . $ROOT . ‘/zzzz/xxxx/mypic.jpg” width=”100″ height=”100″>’; ?>

    you can also use $BASE_URL or bloginfo(‘url’) if you prefer…

    Too messy. The easiest solution, outside of waiting for WordPress to implement such, is to write a filter.

    This needs to happen BADLY. Anyone found a suitable solution?

    I’m starting to think twice before dropping in image placeholders during localhost builds these days because I know I’ll have to redo the links every time I update the live site/DB, which is unfortunate :[

    Cheers guys,

    Hey folks,

    I just made a plugin yesterday for this.

    It uses a shortcode [url] for bloginfo(‘url’) and then does a content filter to substitute the full URL base with [url] when you click Publish or Update.

    By the time the page renders to your visitors, the URL is absolute again in their browser. So this solution should also work if your bloginfo(‘url’)is instead of residing at the / root of your webserver’s DocumentRoot.

    This plugin needs testers, so please try it out.

    Or, if you just want to put it in your functions.php, it’s only 9 lines of PHP.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Relative URL for local images request’ is closed to new replies.