1

I have working on xx.xyz.com then my project is move on xyz.com

In which I have gave in project the previous link is as below

.xyz.com/?page_id=634

And now my link is as belows

xyz.com/?page_id=634

I have tried to put link relative like

../?page_id=634

but its not working. Any suggestion regarding this?

2
  • Can you give some more details? Are you talking about theme files, plugin files or site content?
    – Welcher
    Commented Sep 12, 2014 at 12:48
  • I got its just a /?page_id=634 Commented Sep 12, 2014 at 12:50

2 Answers 2

1

You should be using home_url() ( or something similar ) in your links for theme files when linking to pages. This will allow the domain to change and not affect your hardcoded links - assuming the ID's are the same of course.

<a href="<?php echo home_url();?>/?page_id=634">Link</a>

Good luck!

4
  • Can you mark it answered? :)
    – Welcher
    Commented Sep 12, 2014 at 13:13
  • Sure Why not :) Commented Sep 12, 2014 at 13:14
  • this apparently does solve the issue for the OP, but it is still actually an absolute link. (Just to clarify, for anyone else who might be looking for this answer.) Commented Sep 12, 2014 at 14:27
  • Agreed. However I believe that in this case he was looking for the relative path because he wasn't using the built-in WordPress methods that are made for this sort of thing. Which negates the need ( in this case anyway ) for relative urls.
    – Welcher
    Commented Sep 12, 2014 at 14:32
-2

Declare first page id $page_id = 634; , because you will need it to get page url by id. You can put it directly into the method, but its better to separate it, its more neat.

Than you use ` inside of HTML href element to make a link to the page. You dont need to write absolute link, it is NOT recommended at all. When ever you can, try to avoid apsolute link/path/ etc...

$page_id = 634; 
<a href=" <?php get_page( $page_id ) ?> ">link text</a>
1
  • 1
    You should explain why this code answers the question.
    – cybmeta
    Commented Sep 12, 2014 at 13:34

Your Answer

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

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