Forums

Absolute / Relative path for images (4 posts)

  1. javierazul
    Member
    Posted 7 months ago #

    Hi,
    my "problem" is that when you insert an image into a post is added to the absolute path (src = "http://www.dominio.com/wp-content/uploads/2009/04/imagen.jpg). This doesn't seem appropriate, especially when testing on local and server ...

    I would like to know how to change this to insert the image with the relative path (src = "/ wp-content/uploads/2009/04/imagen.jpg) and not have to do it by hand on each post. Is not this expected in wordpress?

    Thank you.

  2. iridiax
    Member
    Posted 7 months ago #

    Relative URLs do not work in WordPress because your same post content can be accessed through a variety of different URLs (single post, home page, category, feed, etc.).

  3. ggsmith
    Member
    Posted 4 months ago #

    Actually, all images can be accessed with relative url's. The images that come with the wp install are accessed with relative url's - to wp-includes/images and to wp-admin/images. Even tinymce, wp-includes/js/tinymce/plugins/wpeditimage/css/, accesses admin images with a relative "url(../../../../../../wp-admin/images/...)".
    One of the wp forum moderators has said "I've seen some discussion about storing images in a relative fashion but don't know how far that has progressed."

    Personally, on my wp site, I removed the root portion of all the absolute addresses in both tables (a global search and replace in my editor) and everything, all my images and links, now work fine (and I have hundreds).

    There is a plug-in "search-and-replace" which can be helpful to those sites where they build, edit, and/or maintain their site from behind a firewall or from a 'development" installation, perhaps a desktop installation (Javier?). That is not a solution, but it might help to fix all the links and images that are not working right now - if you have no other way of removing the erroneous paths. Using absolute addresses within a website is "generally frowned upon" for good reason. It assumes the site will never move, the website name will never change and, there is never a backup or development site. None of those assumptions are valid. Something does need to be done.

  4. ggsmith
    Member
    Posted 4 months ago #

    It should be noted that the issue is not really relative vs. absolute url's but only keeping hundreds to thousands of hard coded (and outdated/misdirected) copies of them out of the database. For static web sites, the html "base url=" tag serves that very purpose, to accomplish absolute addressing while eliminating the problem of maintaining multiple copies of a constant string (and canonicalization), as does "define('WP_SITEURL', ". In fact, WP_SITEURL (copied into the variable $siteurl) is being used in wp-includes/functions.php already to build the full (absolute) address to an image from the given relative address. The value of WP_SITEURL is in the wp-config.php file - and has been for a long time. It is time for us to start using it.

Reply

You must log in to post.

About this Topic