WordPress.org

Support

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

Relative URL for local images request

  • jblifestyles
    Member

    @jblifestyles

    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" />

    vs

    <img src="http://www.domain.com/wp-content/uploads/filename.jpg" />

    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.

    -Jake

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

    Jason Judge
    Participant

    @judgej

    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 http://wordpress.org/extend/plugins/php-execution-plugin/). 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″>

    or

    <?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.

    ldexterldesign
    Member

    @ldexterldesign

    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,

    Chris Bratlien
    Member

    @chrisbratlien

    Hey folks,

    I just made a plugin yesterday for this.

    http://wordpress.org/extend/plugins/relative-site-url-on-content-save/

    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 http://mysite.com/staging instead of residing at the / root of your webserver’s DocumentRoot.

    This plugin needs testers, so please try it out.

    http://wordpress.org/extend/plugins/relative-site-url-on-content-save/

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

    http://chrisbratlien.com/2010/05/16/relative-site-url-on-content-save/

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