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

I know if I had a page that had a permalink such as /stories/ then I could create a page in my template called page-stores.php and it would load in place of the default page.php when that page loaded (see Template Hierarchy)

What I want to know is if I had that two page templates, maybe page.php and page2.php, if I could use the functions.php file to specify that if a page had a permalink of /stories/ it would use page2.php?

I know there is an option when editing a page to let the end user choose the page template, but in this case I would like to set it specifically.

share|improve this question
up vote 2 down vote accepted

This might work:

add_filter('page_template', 'custom_page_template');

function custom_page_template($template){
  // check your permalink here
  if(get_query_var('pagename') === 'stories')
    return locate_template(array('page2.php', 'page.php')); 

  return $template; 
share|improve this answer
I haven't tested it yet but it looks right. Thanks! – cwd Jun 30 '11 at 3:17

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.