MozaikAgency / wp-theme-starter

WordPress theme starter-kit, build tools included :smile:
MIT License
391 stars 70 forks source link

Not able to view site correctly on mobile device due to it trying to read localhost #261

Closed liberrtines closed 8 years ago

liberrtines commented 8 years ago

I am using MAMP, and when I try to view the site via my mobile using my ip address, all of the assets js/css are using localhost. I've been trying to figure out where I can set the host manually, but haven't been able to figure it out.

Maximilianos commented 8 years ago

I believe that is a more of a WordPress thing rather than something to do with the theme starter. Try this:

Add the following to your wp-config.php right below where it says define( 'WP_DEBUG', true );

/**
 * Change the WP_SITEURL & WP_HOME constants to enable viewing
 * the website from any address without needing to
 * constantly update the database. Yay!
 *
 */
function wp_site_url() {
    $protocol   = ( $_SERVER['SERVER_PORT'] == 80 ) ? 'http://' : 'https://';
    $host       = $protocol . $_SERVER['HTTP_HOST'];
    $app_folder = '';

    $domains_with_subfolder = array(
        'localhost',
        '127.0.0.1'
    );
    if ( in_array( $_SERVER['HTTP_HOST'], $domains_with_subfolder ) ) {
        $app_folder = '/' . basename( dirname( __FILE__ ) );
    }

    return $host . $app_folder;
}

define( 'WP_SITEURL', wp_site_url() );

define( 'WP_HOME', wp_site_url() );

You may need to customise the function to your own specific needs, but give it a go. The $domains_with_subfolder thing is because you are probably serving the site from within a subfolder (eg: http://localhost/awesome-site-1/ and http://localhost/awesome-site-2) add or remove domains from that array to match your requirement.

liberrtines commented 8 years ago

Thank you so much, figured it out!