I have a page on WordPress, it’s slug is http://example/wordpress/page. I also have a second page, and it’s slug is http://example/wordpress/page2.

I want to a link in the first page that links to the second page. So I tried the following:

  • /page2/ – leads to http://example.com/page2
  • /../page2/ – leads to http://example.com/page2
  • page2/ – leads to http://example.com/wordpress/page/page2
  • ../page2/ – leads to http://example/wordpress/page2

But problem is WordPress converts ../page2/ to http://../page2/ which obviously doesn’t work.

So what can I do to fix this? I don’t want to hardcode the url, as the site could be accessed from wordpress.example.com and example.com/wordpress

1 Answer
1

If you can access your page at http://example/wordpress/page2, then use the following code to output a link to your page, no matter what your site url is:

echo site_url('/page2/');

This appends the /page2/ to your website’s url (which is http://example/wordpress/ ), which would be :

http://example/wordpress/page2/

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *