WordPress is somewhat notorious for using absolute URLs in its linking to images and other posts within content. Many have argued for both sides.
It’s quite simple for me: relative URLs are easier for development, absolute URLs are smarter for live websites.
There’s a compromise to be had.
WordPress should add these shortcodes to core:
[home_url]
[uploads_directory_url]
This enables the user and the WordPress editor to insert links to other pages and media on the site while maintaining its given site domain and path. Developers would no longer have to find and replace all instances of the home URL when importing a local database to another environment.
When linking to another page on the site, WordPress could insert [home_url]?p=203,
maintaining a lifetime of environment changes and domain moves without broken URLs.
Or, when linking to an image: [uploads_directory_url]/2013/01/example.jpg
. Actually, I think linking to media needs to be completely rethought (i.e. [media id="100"]
would render whatever image path was associated with that media ID. This would allow you to update an image in the media library and have the image update everywhere it exists on your site).
Update: I wrote a proof of concept plugin for media being inserted into posts with shortcodes to ensure portability.
One reply on “Settling the WordPress Absolute vs Relative URL Debate”
test))