0

I have uploaded a file called page-testtest.php to my template folder. Aren't I supposed to get to this file when I go to example.com/testtest

It seems very strange to me because the documentation clearly states that I should go to that file without any struggle. Instead I get "Oops! That page can’t be found."

By the way the permalink is set as: https://example.com/sample-post/ and I use Underscores template

Before somebody bravely refer me to the documentation this is from https://developer.wordpress.org/themes/template-files-section/page-template-files

page-{slug}.php — If no custom template has been assigned, WordPress looks for and uses a specialized template that contains the page’s slug.
0

A template is not a page you can load directly. A template is used for the formatting ('building') of a 'page' (created via Page, Add) or 'post' (created via Post, Add).

On that page/post editing page, there is a place to specify the template that the WP will use when the page is output. There are default templates used (see Template Hierarchy) for posts/pages.

But you can't call (load into your browser) a template file directly. The template file is sort of 'output instructions' that WP uses to build the actual page (or post).

  • Lets forget "template". I have a file called page-testing.php inside my theme folder. Isn't wp supposed to display that when I type example.com/testing? – user7432810 Apr 19 '18 at 19:19
  • 1
    Your question doesn't provide enough details. But, no, that page won't be called unless you create a page that uses that template. If you want to load that page, then you have to provide the full path to the file, as in example.com/wp-content/theme-name/page-testing.php . You need to read up on Templates and Template Hierarchy (and maybe creating themes, which talks about templates) to understand the concept. Files in the theme folder, if they are defined as themes in their header, are called according to the Hierarchy. If you want a non-WP page to be used, then call it directly. – Rick Hellewell Apr 19 '18 at 19:45
0

Just creating the theme template doesn't create the Page itself. You'll also need to create the Page - typically the easiest way is to just log into wp-admin and manually add it. There are also ways to add it programmatically, but unless you are setting this up for other people who will need these pages added when the theme is activated, usually the manual route is best.

  • wp is supposed to get people to page-{slug}.php when they type example.com/slug. If you thing this is not true please tell me so I find the documentation for that. I thought that was obvious for experts. – user7432810 Apr 19 '18 at 19:01
  • No, WP does not create URLs based on your PHP files. WP looks to see whether it has content in the database that matches your slug. If it does, it then looks through your theme files - from most specific to least specific - to select the appropriate template to parse and display that content. – WebElaine Apr 19 '18 at 19:18
  • Hummm! So what is the importance of page-{slug}.php anyways? – user7432810 Apr 19 '18 at 19:32
  • 1
    It allows you to style a particular Page differently. Other Pages will use the page.php template to display content. – WebElaine Apr 19 '18 at 19:55

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.