2

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

5
  • Hi, i think there might be a problem with your site url and home url options. Check your database and see if both siteurl and home are set to the same value, under wp_options table. Or you can also check from Settings > General.
    – Johansson
    May 17, 2017 at 14:27
  • Hi @Jack, they are the same.
    – CalvT
    May 17, 2017 at 14:29
  • Have you tried changing your page's slug? using page may cause conflict with the WordPress's pagination.
    – Johansson
    May 17, 2017 at 14:32
  • @Jack these are examples, not the real slugs
    – CalvT
    May 17, 2017 at 14:36
  • 1
    Not an answer but a hint: WP always runs under the assumption that is has a certain URL. Making a WP site accessible from multiple URLs will end you in a world of pain in the long run. The issue you're having now is just the tip of the iceberg.
    – kraftner
    May 17, 2017 at 15:15

1 Answer 1

0

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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.