1

I have created a localhost version of my wordpress site on my mac. I now want to test it on various devices over my WLAN network. So, as per other posts on here, I changed this in my wp-config.php

define('WP_HOME','http://localhost:8888');
define('WP_SITEURL','http://localhost:8888');

to

define('WP_HOME','http://192.168.0.19:8888');
define('WP_SITEURL','http://192.168.0.19:8888');

This works as far as it loads the site, css etc but it doesn't load any images (apart from those set as background in css). The db must be working fine because the menu and all the pages and links are working fine, just no images.

So I did a search in the database for 'localhost' and it turned up a load of results in the wp_posts table under the column guid. I've checked the wordpress settings>general and both WordPress Address (URL) and Site Address (URL) are set to http://192.168.0.19:8888

Any ideas?

2

Unfortunately, when changing the URL of your site with Wordpress, you also need to do a pretty big find/replace job in the database: this is because any links or images (and probably a number of other things too) added to posts have absolute (http://localhost:8888/wp-content/uploads/etc.) rather than relative links (/wp-content/uploads/etc.).

Thus, all your images embedded in your posts are still attempting to load from localhost, which doesn't exist apart from on your local computer.

There's a quick and dirty way to fix this: export your database into an SQL file, make a copy, open it in a text editor, and do a find/replace on http://localhost:8888 replacing it with http://192.168.0.19:8888. Then import it again over your existing database (make sure you still have that exported copy of your existing database first!)

This option is quick, and certainly works in most cases for a quick 'check' that things are in order, but it's very likely to kill some of your data, so you'll need to re-import that database export copy once you're done so you can get everything back.

If you're wanting to do this for real - which you certainly will need to when you deploy your site live - you'll need to do a serialised search/replace on the database. Wordpress stores some of its settings (including widget content, for instance) in serialised strings, which basically means if you manually change the content in these strings and it's not exactly the same length as it was before, the content will be lost.

This is a great script that solves that problem and works in most cases. It's not too difficult to set up either. Another option is wp-cli which is easier if you're going to be doing this a lot, but is more work to set up and learn in the first instance.

  • 1
    What a pain! It seems like a better idea to leave the URLs as they are for now. The only reason I want to view it on other devices is to work on the responsive css for phones etc. This still works fine without the images. We have a production site on visual studio which I don't want to mess with so I'll just deploy code to it and leave the image URLs as they are. Thanks for the advice. I'll mark this as the answer for anyone else who comes across the same problem ;-) – The Sumo Apr 13 '16 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.