My wordpress site works fine on my mac via localhost, using Xammp. I want to view the site on my iPhone. So I type in and voila, it brings up my localhost directory. I then click on the site in question and the content is there but no styling or images. I realise that this is because the paths to all the resources is hardcoded into the wordpress database. So when I am accessing the url via on my iPhone, it's looking for all the resources using a base url of localhost/mywebsitename. Localhost path doesn't exist on my iPhone, only does.

So has anyone found a solution to this little issue? How can I see a wordpress installation by ip address and by localhost access?

  • None of your paths should be hardcoded. Make use of functions like get_home_url() or bloginfo('home') among many many others. – Twifty Sep 1 '13 at 20:10
  • possible duplicate of local wordpress blog issues – s_ha_dum Sep 1 '13 at 20:13
  • @Waldermort, the paths are hardcoded by default in Wordpress – Claire Sep 2 '13 at 10:15

You can adapt the site url which is stored in the database based on what domain you are viewing the site from. Add the following to wp-config.php:

define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/yourwebsitename' );
define( 'WP_SITEURL', WP_HOME );

If you use a subdirectory install (ie: you view the site from but the WordPress core files are stored in (or similar), you will need to add this to the second line:

define( 'WP_SITEURL', WP_HOME . '/wp' );
  • that works great. What exactly is it doing though? – Claire Sep 1 '13 at 21:22
  • @Nicola It uses values from the server to tell it what domain is being served, and uses that domain to override the site_url and home options in the database. – shea Sep 1 '13 at 23:28
  • ahh I see. So does wordpress use a constant when getting resources via url, rather than looking in the database for the path? So it does it once and stores it in a constant? – Claire Sep 2 '13 at 10:17
  • No, by default it uses the value in the database which can be changed under the Settings > General admin menu. However, if you define the constant it uses that instead of the database value – shea Sep 2 '13 at 10:43

Yes you won't get style and images until you tell your iPhone to look for an IP instead of localhost.

Your iPhone is searching in


Actually iPhone is searching on its own localhost, not your mac.

First try enter a url manually for an image.

and check if it shows your image.

To make it work permanently, find and replace url string from your database localhost to

Recommend use WP Migrate DB plugin

  • 1
    "To make it work permanently, find and replace url string from your database localhost to" That's changing one problem to another. What happens if he gets a new router with a different IP address? – Twifty Sep 1 '13 at 20:35
  • I don't want it to work on one and not the other, I want to view the site on my mac and my iPhone. – Claire Sep 1 '13 at 21:15
  • It will work on both buy on mac you also need to access it through your IP – Rahil Wazir Sep 2 '13 at 8:58

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.