Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This is a simple question, that's probably been asked before. For internal links between pages, is it better to use a relative link or full permalink?

Thank you.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

It depends on what you're talking about. If you're talking about using just

<a href="/page-title">Page Title</a>, then no. It's better to use the full link.

However, instead of using http://www.domain.com/page-title, it's better to use

<?php echo bloginfo('url'); ?>/page-title.

The reason you don't want to use relative links is the way wordpress permalinks work. If you're on a sub-page (domain.com/about/john) and you use a relative link to another subpage (href="/jane"), it will point to the root URL (domain.com/jane instead of domain/about/jane.

UPDATE

The full <a> will be

<a href="<?php echo bloginfo('url'); ?>/page-title">Page Title</a>

share|improve this answer
    
Hi Josh, Thank you very much for your explanation. Just to clarify, the best way is to do it like so: <a href="<?php echo bloginfo('home'); ?>/page-title</a> ? Did I understand correctly? What if the structure of my site is: domain.com/subpage/subpage/page-title. Would bloginfo('home') find a page that is down the hierarchy? Thank you! –  Laxmidi Jul 30 '11 at 3:47
    
Laxmidi, check my update. You want to have /page-title after the <?php ?> tag, but before the end of the href="" attribute. –  Josh Allen Jul 30 '11 at 3:58
    
bloginfo('home') gets the domain entered in Settings -> General -> Wordpress address (URL) –  Josh Allen Jul 30 '11 at 4:00
2  
bloginfo( 'home' ) is deprecated use bloginfo( 'url' ) instead. See the Codex for proper usage of bloginfo() –  Chris_O Jul 30 '11 at 4:10
    
@Chris_O updated answer to show 'url' instead of 'home'. Thanks for the info. –  Josh Allen Jul 30 '11 at 4:15
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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