How to use relative links on my pages?

$my_url="my/relative/url.php";
echo site_url($my_url);

site_url() when used by itself will return the absolute path to your blog. But, if you add an argument to it, as per my example above, it will prepend the absolute path to your path. Just make sure your URL doesn’t contain a leading slash (eg: /this/may/not/work).

Finally, if you happen to have your wordpress installed in your server’s root, you can use a server-relative path (this uses the leading slash to indicate starting at the server root). So if your blog is installed at http://www.me.com/blog then you can access your relative links safely with /blog/my_link.php.

Leave a Comment