So you want to create a page that looks totally different from your website? Maybe for a blog? Or a gallery? In this quick tip, I will show you how easy that is!

Custom page templates are one of the most handy things available in WordPress, they allow to create custom page layouts to handle certain content. For example, on this website I created a custom template for my Contact page specifically to handle a Google map instead of the text that’s normally displayed on the pages.

So, how do you create a template? There are 2 important parts to this, the first is creating a template:

Create a template

In your default WordPress theme folder, you will have a standard page layout (usually named page.php, funnily enough!) this is the default page layout called by WordPress.

This will look something like this:

<?php
    get_header(); 
?>
 
     <?php while ( have_posts() ) : the_post(); ?>
 
        <?php get_template_part( 'content', 'page' ); ?>
 
     <?php endwhile; // end of the loop. ?>
 
<?php
    get_footer();
?>

Duplicate this page and rename it with the template name of your choice, e.g. contact.tpl.php

Inside the page, you need to specify the template name to get it to show up in the pages section of WordPress admin:

<?php
/**
 * Template Name: Contact
 */

get_header(); ?>

<?php while ( have_posts() ) : the_post(); ?>

    <?php get_template_part( 'content', 'page' ); ?>

<?php endwhile; // end of the loop. ?>

<?php
    get_footer();
?>

It really is as simple as that! But, what if you want to use a different header file, maybe to pull in different scripts etc? Again it’s very simple.

Using custom header files

In your page.php file you will see a line like this:

get_header();

This calls the default header.php file from your theme directory.

To change this to a header for the contact page, we simply call it again with the name as an argument:

get_header('contact');

Now you can duplicate the default header.php file, and rename it header-contact.php to use it!