Something I’ve occasionally found irritating when developing a web site outside of it’s long-term residence (on a temporary URL, in a subdirectory, etc.), is having to choose between either adding relative URLs, the URLs for the current address, or the URLs for the final address for internal links in the development site.
Obviously, using relative URLs will work, but I’m generally reluctant to use them in any CMS (Content Management System), knowing that I may later want to provide access to that content elsewhere on the site. One of the luxuries of a CMS is the ability to use a single source for content which is used in multiple locations, after all — but I don’t much like paying for that with broken links.
However, and especially with a larger web site, it’s not exactly a lot of fun to have to either do a big search and replace or manually run through and replace URLs at the time of launch.
Fortunately, WordPress’ shortcodes API provides an insanely easy way to get around this.
Add this to your theme’s
If you’re not comfortable editing your
functions.php file, you can also download it as a plug-in.
This very, very short line of code will provide you with the simple inline shortcode
[url], which will provide (obviously) the home URL for your WordPress web site.
You can use this in any page or post when you know the URL will be changing like this:
Even if you’re not planning on moving your web site, it’s clear that typing those five characters is probably a much faster way of getting your home URL than typing it out!