Why is WordPress saving full-urls to the database?


Every time im about to put my local project into staging/production environment im beeing hardly reminded that WordPress saves all the urls as absolute.So i need to rewrite all the urls with a SQL-query, or use something like Search-and-replace script.

But why is WordPress doing this?

What is the benefits?

Is it a must for WordPress to work correctly?

There are themes like Roots where there are functions like roots_root_relative_url using preg_replace to remove the full url.

Wouldn’t it be better to only have relative urls, what is the downsides of that?

The benefits of Relative urls in the database can be:
Easy migration from local to stage/production on all links, attachments and so on.
Cleaner, shorter urls in html.

But, Because WordPress doing absolute urls i sure that its good, im only want to now why and why not.

Pontus Abrahamsson 8 months 0 Answers 92 views 0

Leave an answer