How To Use a Custom Page Template In WordPress

Sometimes, it is useful to give a particular section or page of your blog a completely different look and feel from your regular blog theme. It is very easy to do in WordPress.

For example, over on PCMECH I wanted to have a sales page for our premium program. I wanted to make it long-form style and without the usual clutter of the main site theme. As I have stated in the past, when you are in selling mode on your site, you want to get your reader to read the offer and make a yes/no decision. Having a top and bottom menu and a full sidebar is a lot of distraction and a lot of potential ways out of your sales letter without them making a choice on your offer. The solution is to remove all the clutter.

My sales page at PCMech is set up as a page in WordPress. That page, though, uses a completely custom template just for that page. The “how” is actually pretty easy…

Creating a Custom Page Template in WordPress

All WordPress themes have a file called page.php. This is your template file for all pages you have on your blog (remember, pages are distinctly different than posts). The page.php file is your default page template. To create a new one, just open that file in any text editor then “save as” a different file name. In my case, I named the template for my sales page signup_page.php.

Now, at the very top of this new file, you’re going to want a block of PHP code as follows:

<?php
/*
Template Name: [your page name here]

*/
?>

Picture 1This is a PHP comment. Leave the “Template Name:” in place, but you need to change the name of the page. Once you have done that, upload this new file to your blog theme’s folder.

Then, in WordPress, when you go to add or edit a page, scroll way down and you’ll see a setting for “Page Template”. You should see your new page template listed in the dropdown, using the name you entered above. To the right, you can see what my dropdown list looks like in my own WordPress admin panel. I have many different custom page templates in my system, all for different purposes.

Customizing Even Further

At this point, you would have a custom page template, but it would be an exact duplicate of your default page template. So, you would need to customize it. For example, if you want to get rid of the sidebar, just remove the the following line from your template:

<?php get_sidebar(); ?>

You can change any other HTML in this file that you want.

If you want to include different a different header, you would need to hack the code just a bit. By default, the get_header() and get_footer() functions include the default headers and footers for your theme. However, you can replace these with custom PHP includes to any file you want. For example, you could replace:

<?php get_header(); ?>

with this:

<?php include(“header_new.php”); ?>

This would include the file header_new.php from your theme as your header. You would, of course, need to create a file called header_new.php and alter the HTML to make that your new header file for that page.

You can do this same thing for your footer or even your sidebar if you want to include a different sidebar.

Wrapping It Up

The WordPress template system is insanely customizable once you know how to do it. Above is how I have gone about it for my sales page. I have a custom page set up, and it includes a custom header and custom footer (both with stripped down options). I left the sidebar out. In my case, I even put the HTML for the content of the page into the template itself. Inside of WordPress, the content field is blank. I just selected the custom page template, saved the page, and now my signup page works quite well.

Repeat the same basic process for any page of your blog that you want to have a custom appearance. It is so much easier than trying to pack complicated HTML into the editing field of WordPress.

Happy customizing!

Free eBook!

Like what you read?

If so, please join over 12,000 people who receive exclusive online business and blogging tips, and get a FREE COPY of my eBook, Six Figure Blogger Blueprint (PDF and MP3)! Just enter your name and email below:

  • johannabartley

    WordPress isn't easy to manipulate or it isn't for me at least/ I'll try changing the header files using the code you provided. I really hope it will work.
    Domain name registration

  • Ben

    I used this article to add an advertisment into the footer of a page using a Max Banner Ads Pro banner for an individual page sponsor to my site as MBP doesnt support individual page selection. Thanks for your help.

    PS: If there's an easier way using MBP then let me know!! ;-)

  • Jwewrite

    Freak! Thank YOU. The other information I got was much more convoluted than this! So simple and it works without a hitch.

  • Apnataunsa

    Apnataunsa Says this is nice post

  • Nathan

    I am trying to follow the instructions above in order to create a template with no sidebars. However, under my page.php there is nothing that says Where can I find this and how do I get rid of these side bars. I am trying to set up an amazon astore on my site and the sidebars are blocking it.

    Than you for your help

  • http://www.klettervirus.info klettervirus

    What do I do when there is no in my page.php?
    My pages dp have a sidebar, but I don´t find the line to delete :-(

  • http://www.tropicalpenpals.com/blog Tropicalpenpals

    If you can’t find template in the main edit try in the “Quick Edit” its still there.

  • http://www.register-domainname.in/ Domain Registration India

    Really nice tutorial you have shared in this post and this is great explanation about. Thanks for sharing.

  • http://click-india.com Bharatmax

    Thank you very much.Really helps to create beautiful pages.

  • http://entertainment-lobby.blogspot.com/2011/08/iphone-5-concept-leaked-expected-design.html Akif

    Thanks man. Really helps to create beautiful pages.

  • http://twitter.com/Scatteredmusing Debbie

    Thanks this was very helpful :)  

  • http://twitter.com/CodyBWheeler Cody B Wheeler

    Thanks for this man. You’re now my go-to wordpress resource :)

  • http://poojim.com Poojimdotcom

    Thank you for this post. It’s effective with removing comments. However my template has no “”. I think it’s on functions.php. How can I disable sidebar on this case?

  • http://poojim.com Poojimdotcom

    I mean it has no “”

  • http://poojim.com Poojim

    sorry I’m not spamming. I mean it is the php for the sidebar. I don”t know why my comment doesn’t show the php code for sidebar in between “  ” on my previous comments,.

  • Kindergarten Worksheets

    Great post! I have a question-where can I find information
    the formatting of the content of my new pages? Right now in the sidebar is still
    present, even if empty. And I added the text is just plain text right
    now.

  • http://photographya.info/wonderful-butterfly-photography/ Maria Smith

    thanks a lot. I have been looking for this from long time.. and at last i have got it from your site.. 

  • http://photographya.info/ Nina Morgan

    You’re now my go-to wordpress resource :) Nice to know that…

  • http://www.delovesto.com poddys

    Useful tips to help get me going.  I want my site to have a different look if the user views the USA (default) or UK versions.  That means a different home page and sub-pages, but also a different sidebar with content related to the country.  I’m still confused as to whether I need to define different sidebars or not, there are a number of ways to do it I guess.

  • http://photographya.info/best-baby-photography/ Elena Smith

    nice post….

  • http://www.mactonweb.com/ Web design London

    he other information I got was much more convoluted than this! So simple and it works without a hitch.

  • http://www.seogeorgetown.com/ pablodenzel

    thanks you so much for explaining it in complete detail . i was looking for that article .

  • soheila Behyari

    thanks , very useful  :)

  • cvierra

    I’ve created a template but I can’t figure out how to upload it! I’m using the GreenLeaf theme and hosting my site with GoDaddy…could you explain to me how to upload my template to my theme’s folder?

  • http://davidrisley.com David Risley

    You have to use an FTP program. Filezilla.com has a popular one. Also, I believe GoDaddy has a web-based one. It will allow you to upload the file to your server.

  • cvierra

    thank you!