Create a New WP Page Template

Creating a new WP Page or Post Template is easy. It is nice that templates to gallerys, video pages, left templates, right templates, etc are currently available. But, from time to time I like to add a new template that has special CSS attached, or uses the title, content and featured image is a different way

This article talks about the way to add a new wordpress page or post template to your list of template selections.

To create a new template:

  • Decide on a name for your new template.

    The template name must have a special format, the options are as follows:

    • page-{slug}.php
    • page-{ID}.php
    • page-{general description}.php

    The first two naming conventions are used for formatting a specific article. If you have created a page or post and you would like that particular page or post to have a special format, you will create a new file that uses the slug or ID of the page to force wordpress to use the new template on that page/post only. These templates to do not show up in the template selection list, they simply format the specific pages.

    The third naming convention is not mandatory, but, is convenient. The third naming convention is used for a template that you would like to see in the template selection list as you create the new page or post. {general description} should be selected to reflect the label you would like seen in the drop down list of the templates. If you are creating a special format template for creation of landing pages, you might use the general description “landing.” If your description has more than one word (ex: my landings) use a dash(-) in place of spaces in your phrase.

    In our example, we will create a new template called “page-landing.php.”

  • Copy an existing template that is similar to the template you need. If you do not want to start from scratch creating the template, there are several files available for you to start with as a baseline for your new template. You will copy it and rename it to your selected new name. To determine what baselines are available to you, go to your theme directory and look down the list to all the files that have the format page-XXXX.php. Any of these and the file page.php can be used as a baseline. For our example, we will copy page.php to the file named page-landing.php.
  • Modify the existing template.

    To create the new general template, you need only add 3 lines at the very top of the file. At the top of the new file page-landing.php, adjust to say:

    
    
        <?php
        /*
        Template Name: Page: landing    
        */
    
           

    The “Template name: ” label may be followed by

    • Page: {description}
    • Post: {description} or
    • {description}

    Once you are done adding this {description}, it will be added to the list of options available in your templates list and it can be selected from your new dropdown list of template options. Go ahead, modify your template and expect to be able to call on this template to help you whenever you need the new template.

  • Your ready to go. Go ahead and create your next post or page with your new format.

Leave a Reply