I have a local Xampp wordpress installation that I am using as sort of an intranet with some people I work with.
I require them to be able to access it on our LAN router — I found that I needed to change the site url and links from http://localhost:8080 to my IP http://192.168.x.xx:8080 for images and css to show.

However, I have found that when we are connected to a different router, or my travel router, this IP changes and obviously makes it not work on the LAN.
I’m not really wanting to search/replace and change the site name every time a new computer and/or server is hosting the local site.

Question: So I’m really interested to see if there is a way to make the site/home URL dynamic to the hosting computer’s current IP or computername. Or if I’m looking for the wrong type of solution.

I have searched extensively for a solution to this, but I feel my problem is I’m not sure what terms to search for — or if there is a better solution. I hope someone smart could point me in the right direction.

-Based on my internet searches, I have tried a couple plugins – Relative URLs and “Root relative URLS” in hopes it would fix but it has not made a difference.
-I have also set a static IP address in my travel router – however, the problem persists that I would need to change the ip address in the site if the computer changes.
-I’ve also tried this in my wp-config:

<?php
define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST']);
//add the next line if you have a subdirectory install
define('WP_SITEURL', WP_HOME . '/wordpress');

2 s
2

I usually just avoid the issue entirely every time I create a new wordpress site:

define('WP_HOME', "https://wordpress.stackexchange.com/");
define('WP_SITEURL', "https://wordpress.stackexchange.com/");

will cause wordpress to use root-relative urls for everything. Makes site migrations to other domains far easier. Ofc, if you access your site using a folder (eg. “http://<domain>/blog”) you could change them to:

define('WP_HOME', '/blog/');
define('WP_SITEURL', '/blog/');

For existing sites, make sure the database and any theme/plugin files are free from absolute urls generate by wordpress using the old WP_HOME and WP_SITEURL values.

EDIT: just to clarify, you add these defines to your wp-config.php.

Leave a Reply

Your email address will not be published. Required fields are marked *