I have created a new template page and added to the theme's directory where the other pages, archive, comment, author and the rest of the pages are. When trying to go to it via the browser http://mysite.com/newpage.php, I get a 404 page not found error.

What is the proper way to add this page so it is visible and as part of the theme instead of adding it to the root?


Page templates don't work that way.

The way they work is that you create a normal Page, and then select your custom Page Template to display it with. The URL of the resulting Page is determined by the permalink structure and slug you selected.

| improve this answer | |

Templates are not meant to be static pages - the templates are included() when the uri accesses some resource - be that an archive or a specific post/page.

There are two main ways a template gets selected to represent a resource.

  1. Page Templates
  2. Template Hierarchy

When using the Page Template method, you need to specify the correct comments at the top of the template, to inform WordPress that you want this template to be available as a "Page Template". Once that is there, go and create an actual Page in WordPress (by this I mean, a content object of the post_type "page"). Once you have that, you should be able to see a dropdown in the page editor, labeled "Template" from which you can select the template.

Using the Template Hierarchy you would name with the slug or id of the page in he name. This would make the page come up for only that page. Otherwise just naming it page.php would make any page use that template.

There is a third option - which is to intercept the template hierarchy and make it work to your liking. Additionally you can use custom uris to hit specific templates by adding custom rewrite rules and query vars. I wont go into that unless you specifically request that.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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