Templates – intermission

Recently I had to add a page template to WordPress page, and because it took me quite some time of annoyance, I want to post a few details in case it can save someone else time.

Actually all the information can be found on the main page for templates (if you read carefully).

Here is a step by step reference to add a custom template.

  1. Create php file. The name of the file is not important as long as you evade the ‘reserved’ keywords like page.php, index.php etc (see this link link for details). For example, name the file my_template.php
  2. Write the file content. The must-be contains the php header: <?php /* Template Name: template_name */ ?>, where the template_name will be the name of the template that you will see in your WordPress page. Here is an example file content:
    Template Name: Basic template

    <h1>Hello World</h1>

  3. Copy the file to the server. Te file must be in the folder of the the theme that you are using. For example, if you are using theme Twenty Fifteen, then copy the file to folder (default path) /wp-content/themes/twentyfifteen.
  4. Go to your page dashboard and create a new page (Pages->create new). On the right you should have page attributes panel, where a dropbox for templates is available:

page attributes

If you don’t see page attributes: in the upper right corner click screen options and in the panel that opens check Page attributes checkbox:

screen options

If you don’t see the template dropdown, or your template is not on the dropdown list, then the wordpress did not find the template file – check file for typos and make sure the location of the file is correct. On some forums I have also found information that, in this case, you may need to re-activate your theme – go to Apperance->Themes, activate some other theme, and then again activate your original theme. In my case this step was not necessary, though.