WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

Can I specify a template to use with the_permalink()?

Why I need this: when they click a link from a certain page, I want to show that user a different template (extra content) on the linked page.

share|improve this question
So, if I click a link generated in one specific page in your WordPress installation and printed by the_permalink(), you want me to see a different page than if I just enter the URL manually, or get there via any other page? – Pat J Apr 22 '13 at 23:50
Yes, exactly like that. – Phantasmix Apr 23 '13 at 0:06
up vote 1 down vote accepted

The the_permalink() function links to the single post view for the given post-type. As per the Template Hierarchy, the page used to render the single post view is single.php.

So, if you want to modify the template used to render the page when clicking the_permalink(), create/modify single.php, or for a specific post-type, create/modify single-{posttype}.php.

If you want to reference the referring page, you may want to look at hooking into template_redirect, and referencing $REFERRER, or something.

share|improve this answer
Thank you, Chip, referrer worked. Not entirely safe, but good enough for my purpose. Final code: <?php $ref=getenv('HTTP_REFERER'); if (strpos($ref,"domain.com/page")>0) : ?> <p>content for those who came from /page.</p> <?php else : ?> <p>normal content</p> <?php endif; ?> – Phantasmix Apr 23 '13 at 0:25

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.