I've always found it frustrating in Wordpress that images, files, links, etc. are inserted into WordPress with an absolute URL instead of relative URL. A relative url is much more convenient for switching domain names, changing between http and https etc. Today I discovered that if you define WP_CONTENT_URL with a relative url then when you insert files into posts they use the relative url for the src instead of absolute url. Just what I've always wanted! But the official Wordpress documentation says that you should use a full URI if you are defining WP_CONTENT_URL.
Set WP_CONTENT_URL to the full URI of this directory (no trailing slash), e.g.
define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');
Everyting seems to work fine when I use a relative URL, e.g.
define( 'WP_CONTENT_URL', '/my-content-folder');
But is there some problem with using a relative URI? I'm just thinking that there must be a reason for Wordpress stating that it should be defined with a full URI.
I think this is the kind of question only a core developer could/should answer. I've researched and found the core ticket #17048: URLs delivered to the browser should be root-relative. Where we can find the reasons explained by Andrew Nacin, lead core developer. He also links to this [wp-hackers] thread. On both those links, these are the key quotes on why WP doesn't use relative URLs:
Core ticket:
[wp-hackers] thread
And, on a personal note, more than once I've found theme and plugins bad coded that simply break when
WP_CONTENT_URL
is defined.They don't know this can be set and assume that this is true: WP.URL/wp-content/WhatEver, and it's not always the case. And something will break along the way.
The plugin Relative URLs (linked in edse's Answer), applies the function
wp_make_link_relative
in a series of filters in the action hooktemplate_redirect
. It's quite a simple code and seems a nice option.There is an easy way
Instead of
/pagename/
useindex.php/pagename/
or if you don't use permalinks do the following :Post
Page
Category
More information here : http://codex.wordpress.org/Linking_Posts_Pages_and_Categories
What i think you do is while you change domain names, the sql dump file that you have you can replace all instances of old domain name with new one. This is only option available as there are no plugins that will help you do this.
This is quickest way ..
should use get_home_url(), then your links are absolute, but it does not affect if you change the site url
I agree with Rup. I guess the main reason is to avoid confusion on relative paths. I think wordpress can work from scratch with relative paths but the problem might come when using multiple plugins, how the theme is configured etc.
I've once used this plugin for relative paths, when working on testing servers: