WordPress.org

Ready to get started?Download WordPress

Forums

Moving WordPress installation - how to control image urls in posts (10 posts)

  1. abelb
    Member
    Posted 5 years ago #

    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:
    http://codex.wordpress.org/Changing_The_Site_URL

    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="http://www.sitename.com/wp-content/uploads/image.jpg" />

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

    still need to learn svn.

    thanks for any clarification!
    abel

  2. figaro
    Member
    Posted 5 years ago #

    Did you follow the directions under the heading: Domain Name Change in the docs here: http://codex.wordpress.org/Changing_The_Site_URL

    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.

  3. abelb
    Member
    Posted 5 years ago #

    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 (http://wordpress.org/extend/plugins/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?

    thanks!
    abel

  4. figaro
    Member
    Posted 5 years ago #

    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?

  5. syncbox
    Member
    Posted 5 years ago #

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

    like:

    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)

  6. soh3il
    Member
    Posted 5 years ago #

    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

  7. whooami
    Member
    Posted 5 years ago #

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

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

  8. soh3il
    Member
    Posted 5 years ago #

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

  9. figaro
    Member
    Posted 5 years ago #

    @soh3il

    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?

  10. soh3il
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic