WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Hi I am trying to link to some custom templates I have created and I don't seem to know how to do it the right way.For example:

I have created a custom contact page and named it contact.php.From the front-page I want to link to it.Now this is what I did but I don't think this is the best way:

<a href="<?php bloginfo('url') ?>/contact">

Now this works but only if the permalinks are set in the settings page to postname.If for example the page is set to default the links shows the 404.php.

How can I set the links the right way?

I noticed that when creating custom post types there is a way to rewrite the permalinks and define a slug for the new page.Is there a similar way to rewrite permalinks for custom templates?

share|improve this question
up vote 2 down vote accepted

You'll want to use the get_permalink function like so:

<a href="<?php echo get_permalink(get_page_by_path('contact')); ?>">Contact</a>

Which will return the correct URL no matter what your permalink settings are.

share|improve this answer

Your Answer


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.