How To Create A Custom Page Template In WordPress

by · 135 comments

email

This is a follow-on from my article called: How To Make WordPress Look Like a Website, where we walked through changing which page shows up as the home page for your WordPress website. The idea was to make it look more like a web site rather than a blog.

We changed the front page, but were left with the Page title and Sidebar still. So what if we want to completely customize our home page?

WordPress Page Templates are the answer

WordPress provides a clever way to do this called Custom Page Templates. To create a WordPress Page Template, you’ll need to use your text editor. Go to the directory on your server where you installed WordPress, and then navigate to the directory of your theme. Usually that looks something like this: “/wp-content/themes/default” where “default” is your theme name.

That’s where you will create your custom page template file. Create a file called “cover_page.php” and add the following code to it:

<?php
/*
Template Name: Cover Page
*/
?>

<?php get_header(); ?>
Here's my cover page!
<?php get_footer(); ?>
 

The Template Name: Cover Page tells WordPress that this will be a custom page template, where Cover Page is the name that will show up in the drop down selector when you create your page.

The other lines in this file simply include the header and footer of your blog. You can add any HTML that you want to display on your page in the middle.

That’s it – now you have a custom page template!

Creating a Page Based on Your Custom Page Template

Now all you need to do is create a new Page in WordPress:

Add Page in WordPress Screenshot

and assign your new custom page template to it:
Assign page template in WordPress
Now you will have a completely blank home page, with only the header and footer for your site. You can add ANY code you want to this page and customize it until your heart is content.

One caveat though – you’ll find that any content you put into the “page” you created in the WordPress editor will not show up here. Since you are overriding the page with a custom page template, you’ll need to add your content to the cover_page.php file that you created in order for it to show up.

Once you have the page looking the way you want it, go into Settings -> Reading in your WordPress Admin panel and set the “Front page displays” settings to look like this:

Selecting a static home page in the WordPress Reading Settings

Now your custom page will be the first thing visitors see when they come to your website!

Here’s a video walkthrough: Creating WordPress Page Templates.

Update: watch this video to see how to create a custom page template that is editable from the visual WordPress editor!

See my WordPress Powered Websites series for more WordPress articles, tips and tricks for small business websites!
 
 

If you enjoyed this article, get email updates (it's free).

See my disclosure about advertising and affiliate links

{ 127 comments… read them below or add one }

Jami January 2, 2009 at 7:24 am

Nice info! what i’d like to see next are some instruction on how to actually use wordpress as a website — to use your own template and style sheets to create a website in wordpress.

Reply

Toby January 9, 2009 at 10:41 am

Followed the steps and everything worked great. I know there is a way to add a custom size to the page as well but having super issues writing the code on the custom page template. I am trying to frame another page at 800×600 and need the header and footer to stretch to the same dimensions. Any advice or a link where to go would be most helpful. Thanks!

Reply

Luly February 5, 2009 at 3:04 pm

This may sound dumb to those who know the answer, but anyhow:

What’s the use of making cover_page.php if pages that are based on it get over-ridden? How do I make pages with custom content that can be edited within Wordpress based on the cover_page.php template?

I suspect that is done in a more complicated way.
Thanks for any clarification

Reply

Don Campbell February 5, 2009 at 7:07 pm

@Luly – Good question. To make pages that you would like to be able to edit in the WordPress editor, you can just create a WordPress “page” (vs post) and edit it using the rich text editor. But you will have your sidebar and page name, etc.

The only time you would use a custom page template is if you want to completely customize what is shown on a particular page (e.g. the home page of your website.) In this case, you might want to use the header and nav of your blog, but not the sidebar for example, and a custom page template allows you complete control over the content. The disadvantage is that you will be editing HTML to do this.

Does this answer your question? If not let me know!

Reply

jan February 9, 2009 at 4:20 am

…great!!!, but I have a question about it: can I do a custom page with different CSS? (by example, If I want a different background or header in my custom page)

Could you explain me how can i do this?

Thanks

Reply

Don Campbell February 9, 2009 at 10:22 am

@jan – to use a different header, you could choose not to include the < ?php get_header(); ?> in your custom page template, and provide your own code there.

At this point you are essentially editing an HTML file and including your own content, or content from the blog using WordPress code snippets. So you could specify your own CSS stylesheet for the page as well.

Reply

John Solé February 10, 2009 at 8:27 am

How can I add an image to this new “cover page” using, for exemple, Dreamweaver.

I have no problem adding some text, but when I add any image, I can’t see it in th site.

Reply

Don Campbell February 10, 2009 at 10:41 am

John – where are you putting the image? I usually create a images directory off the root of the blog for these images, or put it in the images directory for the theme.

Then you can reference it from your HTML in Dreamweaver. Check in your Dreamweaver site definition and see where it is putting the image.

Reply

JohnMiller February 15, 2009 at 2:15 pm

Don – thanks for all the excellent advice! Here’s a follow-up to your answer to Luly’s question about making pages (using a custom template) that can contain content that can be edited in the WordPress editor.

Is there PHP code that can be inserted into the template that will pull content from the WP database?

I thought a simple would do it, but content entered in the page editor doesn’t show up when the page displays.

Thanks!

Reply

Don Campbell February 15, 2009 at 2:44 pm

JohnMiller – you’re most welcome!

Yes, you can – this is the cool part. You can include any WordPress content you want in the page template.

For example, if you want to show you latest blog posts, you can add this code to the page template: (not in the wysiwyg editor, but in the page template php file itself)

< ?php if (have_posts()) : while (have_posts()) : the_post();?>
   < ?php the_ID(); ?>< ?php the_title();?>
   < ?php the_content('Read the rest of this page'); ?>
 < ?php endwhile; endif; ?>

This WordPress Cheat Sheet has a list of the other WordPress functions you can call to add content to the page.

Reply

JohnMiller February 15, 2009 at 3:01 pm

Brilliant, Don! Thanks for such a prompt and 100% helpful response.

The last par of my previous comment should begun “I thought a simple
should’ve done it – but you understood what I was asking anyway!

I had wondered about putting that in The Loop – but thought that because The Loop is testing for posts, that wasn’t relevant to pages. I guess in WordPress any content is a post – even when it’s in a page!

Reply

JohnMiller February 15, 2009 at 3:08 pm

Sorry, I didn’t allow for the PHP code I was trying to insert being interpreted as code!

Let’s try again:

The last par of my previous comment should begun “I thought a simple [php tag] the_content[php tag] should’ve done it …

Reply

John Solé March 4, 2009 at 3:52 am

I still can’t make an image appear at my cover_page template.

I have this HTML code:

The image is inserted in the “images” directory of the template, and nothing.

What can i do?

Reply

Rob March 4, 2009 at 7:18 pm

Don, I got it. Here are the key points I missed in the tutorial.

The template option only shows up in the classic theme view.
The file cover_page.php needs to saved in the themes directory of each theme you want to use.
When you ftp the file into the theme directory double check the file extension. In my case the file extension was still a .txt file, so I had to manually delete the .txt extension.

Now its up and just need to create the html. Check it out and be my first vistor.
http://www.mobilelandscapingpro.com

Reply

Don Campbell March 4, 2009 at 8:06 pm

Nicely done Rob – I like your site!

And thanks for coming back and sharing your findings with everyone.

Here’s another quick tip (maybe you already know this) – you can change the order that your pages show up on the Nav menu by changing the value in the Order field just below the template drop down when editing a page. Lower numbers show up to the left, with higher numbers to the right.

Reply

Brandon May 5, 2009 at 7:31 pm

Don-

Is there any way to remove the page title with out doing the custom page? I want to be able to edit the page in the WP editor still. There must be some line of code or something somewhere that needs to be tweaked, I have searched and searched to no avail online for an answser. Thanks much

Reply

Sinead May 13, 2009 at 7:33 am

Hello,

I have followed this tutorial and the tutorial at http://wordpress.org/support/topic/268730 but when I go into to choose the template – I don’t have the Page Template drop down list as you have screen grabbed above. It’s not that my new template isn’t appearing – the option is not there at all. Is this something to do with the fact that it is not a default theme? If so is there a way to add a new template using a bought theme?

Much obliged for any help!

Reply

Dean Phillips July 14, 2009 at 4:12 am

Hi,

I am not sure if this has been answered, but when this happens, it can be resolved by reactivating the theme that you are on. Not sure what the issue is…maybe a bug in WordPress.

Thanks
Dean

Reply

Dannah May 13, 2009 at 8:43 am

Thanks for sharing the info. However I’m not to fond of the plain WP page. Can you still do the same thing on a different template like lets say you have a template from freewordpresstheme and you want to use a custom static page from that but not have all the recent comments and such on the side bar. Maybe a video in the sidebar would be ok but nix everything else. Oh and a name and email capture in the side bar would be good too. Is a page like this possible? Thanks

Reply

Don Campbell May 13, 2009 at 8:56 am

@Sinead – Here is a link to a screenshot of where your Page Template drop-down list should be. While editing the Page (make sure your are editing a Page, not a Post), it should be on the right hand side of the page, and look like this screenshot.

Let me know if this doesn’t answer your question, ok?

Reply

Don Campbell May 13, 2009 at 9:01 am

@Dannah – absolutely. Just add this to your page template to include your sidebar:

< ?php get_sidebar(); ?>

Then use Widgets to include things like the opt-in form and other items that you want to include.

Here is a video showing how to add an Aweber opt-in form to your WordPress sidebar.

Reply

Sinead May 13, 2009 at 11:11 am

Thanks Don but nope – it ain’t there.
I made the new template and just uploaded it to theme directory. Am I missing a step? ( or steps!?)

Reply

Sinead May 13, 2009 at 11:16 am

P.S. I have Parent and Order on the right – just no Template.

Reply

Don Campbell May 13, 2009 at 11:21 am

@Sinead – I’ve seen this before. Go to Appearance and select a different theme, like the default one. Activate it. Then switch back to your theme and activate it. See if your page templates show up after doing that.

Reply

Sinead May 15, 2009 at 8:42 am

Hi again. Just to let you know. I did as you said and it worked! Though not until I cleared my cache. Unfortunately, although I now have the drop down I haven’t totally solved the problem. The page is blank. I was following this tutorial [http://wordpress.org/support/topic/268730] to get the Category specific results showing – so I suppose I need to go back there to ask for help ;)

Thanks for your help though.

Reply

Dannah May 17, 2009 at 9:51 pm

Hello, I was wondering if on your business website if you can embed a video on the left where the large picture is on the home page? Thanks

Reply

Don Campbell May 17, 2009 at 9:59 pm

@Dannah, do you mean on the SmallBiz WordPress theme?

Yes, I’ve had several people who use the theme add a video to the home page instead of the picture.

You have to edit the .css, but it is simple and I can show you how. And videos can be added to any other post or page without any customizations.

Reply

Jason August 9, 2009 at 5:27 am

Thanks for this great article. I’m new to WordPress, so this is very helpful. I do have a question. I’ve created the cover_page.php file as suggested, and I have it coming up on my web site. The problem is, before I created this page, I had two tabs at the top of my web site called “Home” and “About”. I now have three called “Home”, “About” and “Cover”. When I bring up the main web site, sure enough…the “Cover” page I created is shown. So when I click on “Home” tab, the “Cover” page is shown, when I click on “About” the about pages is shown, and when I click on “Cover” the cover page is shown again.

I see that I have only two pages, so “Home” must be a default somewhere. Is there anyway that I can have only two tabs… say “Cover” and “About”, or perhaps only “Home” and “About” (with home displaying the cover page that I just created?)

I’ve been around all the WordPress options and cannot seem to see anything.

Thanks

Reply

Don Campbell August 9, 2009 at 9:52 pm

Hi Jason – thanks!
In your Reading Settings in WordPress, do you have it set to a static home page with your new cover page set to be the front page?

Also, if you go into Edit Pages is there a page called Home? If so, try setting that to unpublished and it should disappear.

Also, which WP theme are you using?

-Don

Reply

Jason August 12, 2009 at 4:16 pm

Hi Don,

Yes, I have the reading settings set to have a static home page, and this is set to “Cover”.

I don’t have a page called “Home”, so I therefore can’t set it to unpublished.

Could the WP theme template be creating this “Home” page? The theme I am using is: Piggie Bank 1.2 by Lorelei Web Design

Thanks for your help.
-Jason

Reply

Jesse August 12, 2009 at 9:10 am

I know this is a ridiculously basic question, but how do I “Go to the directory on your server where you installed WordPress, and then navigate to the directory of your theme.”

I’m using Bluehost, if it helps knowing that.

Thanks in advance,

Jesse

Reply

Don Campbell August 12, 2009 at 9:23 am

Jesse – good question, and yes knowing your hosting provider helps. In Bluehost, your directory probably looks something like:

/public_html/blog/wp-content/themes/themename

Where blog = the directory you installed WordPress in (or if you installed it in the root of your domain, then you don’t need this directory.)

And themename = the name of the them you are using. The default WordPress theme would be “default”, if you are using my SmallBiz theme then the directory name would be “smallbiz”.

Does this help? If not let me know.

Reply

Kawika August 16, 2009 at 6:47 am

Hi Don,

Fantastic posts so far. I had a fairly simple question but cant really find any information. When creating additional content for a wordpress “site” do you write posts or pages?

Can “pages” be pinged the same as a post would? Is there any advantage over using a post over a page?

Thanks!

Kawika

Reply

Don Campbell August 16, 2009 at 2:59 pm

Good question Kawika.
Typically you would write new “posts” for your blog. Posts are considered “updates” or new information posted to your website. Pages are typically used for more static pages on your site, like the “About” page or “Contact” page.

There are no real advantages of one over the other as far as the search engines are concerned. Both can have trackbacks and pings.

I hope this helps!
-Don

Reply

TK August 27, 2009 at 2:34 am

Hey Don,

If I put the custom page template inside a directory inside the my theme’s folder will it still work. I plan on making a ton of these custom templates and don’t want them to appear on the theme editor.

Thanks

Reply

Josh August 21, 2010 at 12:42 pm

This is an old post but hopefully OP will pick this up. I really need to do the same as asked here by placing custom page templates within another directory as I have over 90 custom page templates it quickly becomes confusing when trying to navigate through the minefield of templates.

I would like to be anle to keep core theme files in the main directory and call custom page templates from another directory but haven’t yet figured out how.

Josh

Reply

Don Campbell August 21, 2010 at 1:01 pm

@TK, @Josh,
I tried it and WordPress does not pick up the page templates in a sub-folder underneath the theme (or any theme.)
-Don

Reply

Andrea September 11, 2009 at 5:27 am

Hi Don,

I’d like the blog page to have a different header than the other pages, so I created a custom page template (called “Blog Page”) that calls a custom blogheader.php (with the new image). I also registered a new sidebar just for the blog page with different widgets than those on my other pages and added the different widgets in the WP admin. In the Pages edit menu I selected the blog page to edit and applied the “Blog Page” template from the drop-down menu on the right. But it’s not working. The blog page still looks the same as all the others. I’ve tried creating other completely new templates (all of which show up in the drop-down correctly) and applying them, but the pages are still using the default no matter what. What am I missing?

Thanks so much…

Reply

Andrea September 11, 2009 at 5:38 am

Follow-up with more info: When I change my Posts page (in Reading) to any page other than my current blog page, then go to the blog page, the template applies correctly. Is that what’s wrong? A Posts page won’t apply a custom page template?

Reply

Pat September 28, 2009 at 4:01 pm

Hi Don,

Excellent post.. You answered exactly what I needed to know…

For testing, I left the text as “Cover Page…” ,etc.. When I pull up the Home page, everything is as it should EXCEPT, the white background disappeared, and I simply have my text on a black ground…

When I tried to insert the following HTML:

The background doesn’t appear as white… Am I doing something wrong?

Thanks,

Pat

Reply

Don Campbell September 28, 2009 at 7:45 pm

Hi Pat – thanks!
I can’t see the HTML you posted. Which theme are you using? Did you include the header in your custom page template?

Reply

m a r c o September 28, 2009 at 8:45 pm

How about plugins and addons for “static” WordPress created websites. Any suggestions? Most of the cool stuff out there is related to posts…

Reply

River January 5, 2010 at 1:29 pm

Don,
Just discovered all the information you have posted…I’m seriously $$ crunched and forced to a DIY creating my website and blog. If not so jammed I would pick up you website template…and probably will as personal finances improve…in the meantime, kudos to you for posting very helpful information!! And, also sorry, this is not the place for that but wanted to get it to you.
river
@riverrance

Reply

Gary January 7, 2010 at 10:30 pm

Well, I must say Don….. I’m hooked.
Wish I’d found your site a long time ago. I’m a bit of a tweaker myself but the amount of time that takes when you’re experimenting every step of the way (well, almost) is considerable. You obviously have the technical skills to understand the code PLUS the knack of writing clear explanations.
Bravo.
I’ve subscribed to your weekly newsletter and will be looking out for each issue.
Gary

Reply

Don Campbell January 8, 2010 at 7:02 pm

@River – thanks for the feedback, I appreciate it. Let me know when you get your DIY site up and running, I always like to see them.

@Gary – thank you; that means a lot! Welcome, and I welcome your feedback too – if there is anything else you would like to see videos or tutorials on just let me know!

Reply

Hamish March 4, 2010 at 8:48 am

Don, This always happens to non-nerds like me: your advice: ‘WordPress provides a clever way to do this called Custom Page Templates. To create a WordPress Page Template, you’ll need to use your text editor. Go to the directory on your server where you installed WordPress, and then navigate to the directory of your theme.” – assumes that I know how to get to the directory on my server and then how to navigate to my ‘Theme”. I called GoDaddy to see if they could help me find that directory, and they told me that you were probably referring to those who host with WordPress. Is that right? If so – then what are the instructions for those who don’t?

Also – on Themes – I went through the whole thing and did ‘install’ and received confiration that it had installed – yet my site still looks like the bare-bones ‘wordpress’ blue banner with words on it. What do I have to do to make the theme show up? Many thanks, Hamish.

Reply

Don Campbell August 28, 2010 at 12:08 pm

@Hamish – no this tutorial is for self-hosted WordPress sites like your, not WordPress.com sites. To get to the folder where your WordPress theme is installed, you either need to use an FTP program, or in GoDaddy you can use their File Explorer to do it. You can access that by logging into your GoDaddy account.

If you want to upload and activate a new theme on your WordPress site, this video shows you how – How to Install Themes in WordPress.

Reply

Dannah March 29, 2010 at 7:42 pm

Hey Don, I was wondering how to remove the date feature from the blog. I have the Date Exclusion SEO plug in but it’s not working on the E2W Theme. Is there something else I can do to remove it?
Thanks, Dannah

Reply

Don Campbell August 28, 2010 at 12:13 pm

Dannah,
The best way to do this is to hide the date using CSS. Find the class or id and then add a display:none to it in your style.css then it will not show up any more.

Reply

Jerry April 5, 2010 at 4:18 pm

Hi Don,

First off thank you so much for your wealth of knowledge. I created the custom page that you showed us how to make. I would like to add links or pages at the bottom for About, disclosure, privacy etc. How do I create those to show up on the custom page and in the footer area. Hope that makes sense…thanks, jerry

Reply

Don Campbell August 28, 2010 at 12:15 pm

Hi Jerry,
It depends on the theme you are using, but probably in your footer.php.

Reply

Alex May 9, 2010 at 5:36 am

Hi, Don, many thanks for sharing this with us! I’m working on a project for creating a small business website on the WordPress platform and I find your info useful. I tried your method, and it worked, bu then I just decided to include my html code directly into the page.php :) )
I have a question, however- about including info from the WP database into our templates and cover pages. Could you write the code fragment for inserting the whole information (text, images etc) from a static page called “Home” into the template? (If it matters, the permalink of the static page is host/wordpress/index) ?
Thank you very much!

Reply

Don Campbell August 28, 2010 at 12:27 pm

Hi Alex,
This video shows you how to set up a page template where you can edit the contents of the page with the WordPress Visual Editor: A WordPress Page Template You Can Edit!

Reply

Abdul Wakeel May 30, 2010 at 3:28 am
Don Campbell August 28, 2010 at 12:20 pm

Abdul,
It’s different for every theme until WordPress 3.0. Once you upgrade to WP 3.0 you can change the background image easily in the Appearance section of your WordPress Admin.

Reply

John July 6, 2010 at 8:42 am

So, I’ve made templates like this all the time, but for some reason on this one particular site im working on the code:

Will NOT show up when I try to assign a the template to a page in the back end, It doesn’t even bring up the drop down list. Does anybody know why that is? PLEASE HELP!

Reply

Don Campbell August 28, 2010 at 12:23 pm

Hi John,
Did you give the page template a unique name in the comments at the top of the PHP file? That is usually the problem when you page template does not show up. Also, it needs to be in the same folder as your theme files.

Reply

Erwin July 28, 2010 at 11:50 am

Great!!, thank for the info.

Reply

Blog Setup Service August 19, 2010 at 1:10 am

That’s impressive. I’ll apply these on my sites. Thanks

Reply

Doug C. August 28, 2010 at 12:02 pm

Nice tips. Unfortunately when I save my PHP page file to my server in the theme folder it does not appear in the Template drop down. In fact, the only thing that does appear in the drop down is a One-column template that came with the theme, and that’s it.

Reply

Don Campbell August 28, 2010 at 12:28 pm

Doug – Do you have a unique name for the page template in the comments at the top of the Page template php file?

Reply

Doug C. August 28, 2010 at 12:34 pm

Yes.

Reply

Don Campbell August 28, 2010 at 12:39 pm

Ok, it could be a problem with the theme. What theme are you using?

Reply

Doug C. August 28, 2010 at 12:46 pm

2010 Weaver. Here’s a link to the developer’s page: http://wpweaver.info/themes/twenty-ten-weaver/

Reply

Don Campbell August 28, 2010 at 12:54 pm

Doug, where are you putting your page template php file. In the parent theme’s folder or in the child theme’s folder?

Reply

Doug C. August 28, 2010 at 1:51 pm

Doh! I was putting it on my server, lol. It has to go in the theme folder on my client’s server. Good grief. I need more sunlight on my brain. Ok, so I put it in theme folder on my CLIENT’S server and now it appears in the drop down.

So what’s next?

Reply

Leave a Comment

{ 8 trackbacks }

Previous post:

Next post: