Why does WP not use relative links when linking pages?

Why is it that WordPress 4.4.2 does not use relative links (get_bloginfo, or such things) when I use the “internal editor mechanism” to link to existing pages and posts in a site.

My local WAMP environment sits under localhost. However, when I after some time developing use this in my wp-config…

define('WP_HOME','http://192.168.0.101/mysite');
define('WP_SITEURL','http://192.168.0.101/mysite');

…to be able to access my local environment from mobile devices over LAN, all links to pages and posts break, and I have to rewrite permalinks in order to get them working again. This is normal and not my question.

The thing that puzzles me is that even after rewriting the permalinks, some links remain broken. Namely, those that have been created in the internal editor by linking to “existing posts and pages”. IIRC the same problem exists when moving from dev to production. One would think WP would be able to understand that these links are also within the site, just as menu items etc…

1) Why does WP not understand this?

2) Is there any way to prevent it, short of directly editing the DB or using a plugin to do the same?

1 Answer
1

Your question seems to have been already answered by a user here:
https://stackoverflow.com/a/18516783/844732

However it sounds like your problem would be solved by using this plugin:

Relative URL

Relative URL applies wp_make_link_relative function to links to convert them to relative URLs.

Yoast also has some background on relative URLs.

Leave a Comment