Wordpress will only fully load on localhost

2019-03-17 00:37发布

问题:

I have recently set up wordpress on my wamp server and when loading up the webpage through localhost it will always fully load up the entire page but when i try to access the webpage through anyother computer (even if the computer is connected to LAN ) it will only render like an HTML template, no pictures are rendered, only the box outlines,

It appears that the site is not loading up css files while online, but then i am wondering why it would work on the local host.

I have tried re installing wordpress from wordpress.org, and fully looked at the instructions and have tried to look online for some answers, but came up blank

computer information:

WAMP server Dreamweaver

*could the problem be from dreamweaver during the site set up?

回答1:

The way to make a localhost install work on other computers on the network you need to do a couple things.

  1. The localhost needs a dedicated address either IP or fake domain.

  2. WordPress needs to be configured with that address

  3. the other machines need to be told where that address is, usually in the hosts configuration file like

192.168.30.1 wp.dev

where the above is an network IP assigned to your localhost with WAMP and wp.dev is the fake dev domain. This pretty much needs to be set on all machines so they know where the host lives.



回答2:

I saw a question very similar to this one but for Mediawiki today. You probably have configured Wordpress with 127.0.0.1 or localhost as your IP address, instead of your actual IP address.

You have to make changes in your wp_options table, you need to change two entries: option id 1 - siteurl - change http://localhost/ to http://<your local ip>; option id 36 - home - change http://localhost/ to http://<your local ip>



回答3:

the main issue is because wordpress use the server address from database, wordpress use the root url from the database option named home and siteurl so if you try access wordpress outside their computer it may get the incorrect path for css and javascript.

if you want to get correct path without doing redirect, you can defining the dynamic root url under wp-config.php

add this script below the define('ABSPATH', dirname(__FILE__) . '/');

/**
 * get home url from absolute path
 * @return string url to main site
 * hello@lafif.me
 */
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['HTTP_HOST'];
    $home_url  = "${protocol}://${domain}${disp_port}${base_url}";

    return $home_url;
}
$url = get_dynamic_home_url();
define('WP_SITEURL', $url);
define('WP_HOME', $url);

i think that would be worked with http://localhost/, http://localhost/wp/, http://127.0.0.1/, or http://yoursite.dev/



回答4:

Sounds to me like your theme's got some incorrect paths for assets like images/stylesheets.

That would cause the sort of problem you're having, I think. You should post the sections of your code (in your theme) that you're using to load things like images/CSS.



回答5:

You have to configure the general option form inside the administration page from your wordpress admin access and replace the localhost urls with the correct information.

For instance, replace localhost with http://my-site.my-domain. In case of no domain a local hostname is used inside page's code, that why you can't access from other computers. Consequently the configuration of admin page is mandatory for the web site urls after the 5min installation wordpress.