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

I want to be able to render post in two different styles (2 templates).

For example, let's say I have the post ID 133, I would like two URLS to access it and so it renders where different template would apply.

  • lorem.com/render1/133
  • lorem.com/render2/1333

for example... or it could be something like:

  • lorem.com/post/133
  • and lorem.com/post/133?template=2

How would you do it?

share|improve this question
Just a heads up, a query var (your ?template=2) example might be safe, but be careful about duplicate content. If WordPress correctly adds the canonical address meta tag, I think you'll be safe, but it's better to avoid the issue than suddenly find your site tanked on Google overnight. – mrwweb Jan 18 '13 at 16:52
up vote 0 down vote accepted

Your best bet would probably be the Rewrite Endpoints API. The API allows you to create post URLs with endpoints like lorem.com/post/133/json/ or lorem.com/post/133/print/. You'll find useful code examples in the link provided.

share|improve this answer
Clean. Perfect. – flintsburg Jan 20 '13 at 12:10

If you add a query arg, via add_query_arg(), you could then query that query arg, via get_query_var(), inside of a callback hooked into template_redirect.

(Note: how/why you add the query arg is outside the scope of this answer.)

For example:

function wpse82168_template_redirect() {
    // You'll need to update these conditionals according to your context
    if ( is_single() && get_query_var( 'template' ) && '2' == get_query_var( 'template' ) ) {
        get_template_part( 'template-2' );
add_action( 'template_redirect', 'wpse82168_template_redirect' );
share|improve this answer
Interesting technic :) Is there a particular explanation for you function name (wpse82168_template_redirect) or it's just random? – flintsburg Jan 20 '13 at 12:03
All declared function names are, ultimately, arbitrary. But in this case, wpse82168 refers to this question, and template_redirect refers to what the function does. The former is a unique prefix that ensures the function is properly namespaced; the latter is inherent documentation, in which simply reading the function name helps explain the purpose of the function. – Chip Bennett Jan 20 '13 at 13:49

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.