Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm making a mobile site and I'm using the main computers IP adress to connect to it from the iphone

With normal sites it works fine, but the WP site I get is stripped from CSS, JS, and images, only plain text. on the mac and the iphone-simulator it works fine.

Is it something known and configurable?

share|improve this question
Can you access the site by typing in the same IP address on the server, eg. "";? – Miljenko Barbir Jun 14 '12 at 16:05
@MiljenkoBarbir Yes, it works fine with ip from the same computer – ilyo Jun 14 '12 at 16:19

2 Answers 2

up vote 0 down vote accepted

yes, it because wordpress use the server address from database get_option('siteurl') and get_option('home'), so if you access the wordpress from IP Address the assets (js and css) will still loaded from localhost/wp/ that mean from not the

the simple way to get dynamic url for your wordpress is defining the site_url and home_url on wp-config.php with function that parse the request and get the correct root url for your wordpress

try to add this script below the

/** Absolute path to the WordPress directory. */ if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/');

 * get home url from absolute path
 * @return string url to main site
function get_dynamic_home_url(){
    $base_dir  = ABSPATH; // Absolute path
    $doc_root  = preg_replace("!${_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME']);
    $base_url  = preg_replace("!^${doc_root}!", '', $base_dir);
    $protocol  = empty($_SERVER['HTTPS']) ? 'http' : 'https';
    $port      = $_SERVER['SERVER_PORT'];
    $disp_port = ($protocol == 'http' && $port == 80 || $protocol == 'https' && $port == 443) ? '' : ":$port";
    $domain    = $_SERVER['SERVER_NAME'];
    $home_url  = "${protocol}://${domain}${disp_port}${base_url}";

    return $home_url;
$url = get_dynamic_home_url();
define('WP_SITEURL', $url);
define('WP_HOME', $url);
share|improve this answer

It may be a conflict between the internal option 'home' or 'siteurl' and the access per pure IP address. WordPress doesn’t use just any server name, there is some redundancy which may get in your way here.

You can try to resolve that by two constants defined in your wp-config.php:

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

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

These constants should outdo the options from the database.

share|improve this answer
This is almost certainly the right answer. Odds are, your CSS/JS/IMAGES are not being "stripped", but are being referenced using whatever domain the site is assigned to on your computer (which your phone can't access properly, but your computer can--which is why it appears to work on your computer via the IP). As an additional note, if you have images embedded in any of your posts, they won't be visible on your phone, even if you implement toscho's fix, as they'll have the domain hardcoded. – MathSmath Jun 14 '12 at 18:46
@MathSmath Yeah, you’ll need probably a filter for the whole output and strip or replace the server name from all paths. I think I have written a plugin for that, just can’t find it right now. – toscho Jun 14 '12 at 18:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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