How to create custom Post Templates with WordPress

Martin Brinkmann
Jul 9, 2012
Updated • Jan 1, 2013
Development
|
5

Sometimes you may want to customize the post template of a WordPress post. This can be the case for instance when you want to add something to the page the post is displayed on that should not appear on other post pages, or if you want to remove something, e.g. advertisement.

In the past, we have shown you how you can create custom tag pages and custom headers for categories which can be very helpful in this regard as well. These custom pages allow you for instance to add unique content to important pages to provide visitors with additional information.

The WordPress plugin Custom Post Template is ideal for our purpose. While it still requires you to add a new php file to your WordPress theme directory manually, you can afterwards use it comfortably from within the WordPress admin dashboard.

First thing that you need to do is install the Custom Post Template plugin on the WordPress site that you want to use it on.  I have tested it on the latest available version, 3.4.1 at the time of writing, and it is working without issues there. Once you have installed and activated the plugin in the dashboard, fire up an ftp program and open the WordPress theme folder in it.

Now, the easiest way to create templates is to copy and rename the single.php file of your WordPress theme. You can name it any way you want, but I'd suggest you select a name that is easily identifiable.

Once done, edit the newly created file and add the following information at the very top of it before any other content:

<?php
/*
Template Name Posts: noads
*/
?>

Replace the noads name with a name that you can identify the template by.  You can now make modifications to the post template, like removing ads or adding advertisement to it. Save the file afterwards and repeat the process for as many template files as you want.

When you now open an existing post in the dashboard or write a new one, you will see a Post Template module on the page that you can use to switch from the default WordPress template to a newly created one.

post template wordpress

I'd suggest you verify that everything is in order by previewing the post before you publish it on the site. This is especially important at the first time to make sure that everything has been configured correctly in the template file.

Advertisement

Previous Post: «
Next Post: «

Comments

  1. mark shirley said on July 26, 2012 at 2:24 pm
    Reply

    But it strips out the styling of twenty eleven child theme how can I keep this

  2. Mike said on July 10, 2012 at 10:25 pm
    Reply

    Thanks for this! custom post types are one of the most useful tools!

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.