Support » Fixing WordPress » Moving WordPress installation – how to control image urls in posts

  • I am running WordPress 2.7 on my website.

    I have been working locally on my MAC running Leopard using MAMP and a virtual host to create a local test environment.

    When I moved the installation over to my the production server, I changed the siteurl in the wp-admin on my local environment, exported the database from phpmyadmin and imported it into the phpmyadmin on the production server and changed config file.

    Everything was cool except for all the images were being called with absolute urls pointed to the local environment url and not the live url.

    I followed the directions under Domain Name Change on this page:

    but it did not fix the issue.

    Why does WordPress embed an absolute url into the image url and image links in all the posts?
    Is there a way to make the links relative so it is just

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

    instead of
    <img src="" />

    just trying to figure out the best way to work between local and production environments.

    still need to learn svn.

    thanks for any clarification!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Did you follow the directions under the heading: Domain Name Change in the docs here:

    It seems that should change all your url’s in the database. I have never used this process. What I do, is simply open the database dump in an editor and do a find/replace to change all the url’s….have done this multiple times and it always works for me.

    I did follow those instructions form Changing the Site URL but just under changing the domain name.

    I also tried the find and replace in an editor. On my site, i also have the plugin cforms ( running and when i would find and replace and upload the new database, i would get a major cforms error that would kill my forms(something to the effect of error in an array)

    I think i may need to just practice with a fresh install because i have moved this database around a few times from local environment to production server and back to learn how to update WP from 2.6 to 2.7 and im guessing i messed up somewhere along the way.

    so just to be clear, image filepaths do show up in the source code as absolute paths?


    so just to be clear, image filepaths do show up in the source code as absolute paths?

    I don’t recall without downloading one of my db’s and looking….but you could look in your downloaded db and tell…right?

    couldn’t you just use the blog_info(‘template_directory’) function?


    href="<?php blog_info('template_directory')?>/the rest of the path to the image/name.gif"

    That way, it doesn’t matter what template you use and the references infer the /wp-content/theme/yourtheme/blah blah

    And even if you use that, or the http reference or the /wp-content/theme/yourtheme/ method, the source code parses the path and displays it using the external http:// path… as far as I know.

    update: just caught that you are talking about paths IN your posts, assuming made from the write post admin page… you can reference those using /wp-content/theme/yourtheme/rest of path or /wp-content/uploads/ if that is where they are kept… if not using the media library to upload and access images.

    And you can change where those images are stored in your settings (from the uploads folder)

    You can not use <?php blog_info(‘template_directory’)?> on your URL, php is a server side language which means that it should go to the server, process & translate & then get back to where it was. but in this case, it is a plain text.

    I have a same problem with my images when I’m developing on localhost and still I’m worry what am I gonna do when I want to make my blog live on a domain name.

    But If you insist to use relative paths, I found a solution:
    Parent path for relative path has a direct connection with a parmalink.
    so depends on how you customize your parmalink to show up, you can create a folder, call it whatever your parmalink is, and put your images there, for me, my parmalink is like blog/%postname%
    so I uploaded all of my images into the blog folder, and here we go, all images are working now. you can also create a folder inside blog and call it images, so when you are inserting images into your post, you have to indicate images/picture.png




    You can not use <?php blog_info(‘template_directory’)?> on your URL ….

    youre wrong, and yes you can use syncbox’s solution.

    I did try <?php blog_info(‘template_directory’)?> but it didn’t work.


    Why not just do a search/replace on the database before you upload to your live site? I’ve never used custom parmalinks, but wouldn’t this work just as well with them?

    Thanks Figaro,

    Yes that’s the possible solution, but as I prefer to work on my development area, and I’m not only working on one blog, I prefer to have a dynamic website which doing a replace is give me a feeling that I’m doing stuff manually. but seems that’s the ultimate, and easy way.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Moving WordPress installation – how to control image urls in posts’ is closed to new replies.