Support » Fixing WordPress » Absolute / Relative path for images

  • Hi,
    my “problem” is that when you insert an image into a post is added to the absolute path (src = “ 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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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.).

    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.

    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.

    I just would like to point out that you could simply write a tiny plugin with this code:

    function relativePathForUploads($fileInfos)
    	global $blog_id;
    	$path = get_blog_option($blog_id,'siteurl');
    	$fileInfos['url'] = str_replace($path,'',$fileInfos['url']);
    	return $fileInfos;
    add_filter('wp_handle_upload', 'relativePathForUploads');

    That will store all uploads as a relative path.

    *tested on MU 2.8.6

    Thanks all,

    I appreciate the help here.

    Unfortunately, what if you do not know how to write a tiny plugin?

    I had the same problem and stumbled upon this thread. Eventually it seemed that you can determine the ‘Full URL path to files’ at the ‘Settings > Miscellaneous’ page to ‘/path/to/your/uploads’, this way inserted images get a ‘/path/to/your/uploads/image.jpg’ href.

    Best of luck!

    The method I use for relative images is really simple, just add a few lines to functions.php:

    Am having problem with my image, whenever I insert image in my post it won’t show. Sometime when I align the image to left or right with the post, the space will be there but the image won’t show.
    I don’t know whether the problem has to do with location/directory file.

    I have tried fixing the problem from Setting> Miscellaneous settings.
    This is what I have in Store uploads in this folder (/home/naijajob/public_html/wordpress/wp-content/uploads)

    I wrote this in Full URL path to files (

    When I upload the image, the image file is like this:
    after uploading I will not see the image even on Edit Media Panel, but other information are there like file name, file type, dimension and Location of the uploaded file.

    If I check the location of the uploaded image from browser, it say: page error-
    Whoops! That Page Isn’t Here

    Please someone tell me what to do

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Absolute / Relative path for images’ is closed to new replies.