How to use relative links on my pages?

In my web pages I want to use relative links instead of absolute links.

However, pages do not allow php code inside them, so i cannot do to from a url in a relative manner.

How does one get relative urls inside wordpress pages so that changing domain names wouldnt affect the links?

8 s
8

$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