Create a Custom Page Template in WordPress

Do you want to create a custom page in WordPress? You might notice that many WordPress sites have different layouts for different pages. A custom page allows you to have different layout in appearance from regular pages in WordPress. In this article, we will show you how to create a custom page in WordPress.

What is a Custom Page in WordPress

By default WordPress allows you to create posts and pages. Your WordPress theme controls the appearance of your pages by utilizing a template file called page.php.

This template file affects all single pages that you create in WordPress. However, not all pages are the same. Little changes in their layout and appearance can make them unique and a lot more useful.

Creating a custom page template in WordPress requires a basic understanding of HTML, CSS, and PHP.

Having said that, let’s jump into creating your first custom page in WordPress.

Creating a Custom Page in WordPress

First, you need to open a plain text editor like Notepad on your computer. In the blank file add this line of code at the top:

<?php /* Template Name: CustomPageT1 */ ?>

This code simply tells WordPress that this is a template file and it should be recognized as CustomPageT1. You can name your template anything you want as long as it makes sense to you.

Once you have added the code, save the file to your desktop as, custompaget1.php.

You can save the file with any name, just make sure that it ends with .php extension.

For this next step, you will need to connect to your website using an FTP client.

Once connected, go to your current theme or child theme folder. You will find it in /wp-content/themes/ directory. Next, upload your custom page template file to your theme.

Now you need to login to your WordPress admin area to create a new page or edit an existing one.

On the page editing screen, scroll down to ‘Page Attributes’ section, and you will find a template drop down menu. Clicking on it will allow you to select the template you just created.

Now if you change template and visit this page, then you will get to see a blank page. That’s because your template is empty and does not tell WordPress what to display.

Don’t worry, we will show you how to easily edit your custom page template.

Editing Your Custom Page Template

Your custom page template is like any other theme file in WordPress. You can add any HTML, template tags, or PHP code in this file.

The easiest way to get started with your custom page is by copying the existing page template provided by your theme.

Open your FTP client and go to your theme folder. There you will find a file called page.php. You need to download this file to your computer.

Open the page.php file in a plain text editor like Notepad, and copy all its content except the header part.

The header part is the commented out part at the top of the file. We are not copying it, because our custom page template already has one.

Now you need to open your custom page template file and paste it at the end.

Your custom page file would now look something like this:

<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        // Start the loop.
        while ( have_posts() ) : the_post();
            // Include the page content template.
            get_template_part( 'template-parts/content', 'page' );
            // If comments are open or we have at least one comment, load up the comment template.
            if ( comments_open() || get_comments_number() ) {
            // End of the loop.
    </main><!-- .site-main -->
    <?php get_sidebar( 'content-bottom' ); ?>
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Save your custom page template file and upload it back to your theme folder using FTP.

You can now visit the page you created using custom page template. It will now look exactly like your other pages in WordPress.

You can now continue editing your custom page template file. You can customize it in any way you want. For example, you can remove the sidebar, add custom PHP code, add any other HTML you want.

You can add the content by editing the page in WordPress page editor screen. You can also leave the content area in page editor completely empty, and add custom content directly in your page template.

Create a custom Header, Footer or Sidebar for Each WP Category

Have you ever seen WordPress blogs that have a separate header for different categories? We’ll share here a simple snippet that you can use to add custom header, footer, or even sidebar for each WordPress category.

To call a particular header, you will need to open your index.php and replace your normal header code with this one:

This code above is basically telling WordPress that if someone opens the category called “Blogging” then WordPress needs to display a file called header-blogging.php if it exist. If it does not exist, or if the category is not blogging, then WordPress displays the default header file.

To get a separate sidebar for each all you need to do is add the following code:

The code above will look for sidebar-blogging.php to replace the default footer file if the category is Blogging.

To get a separate footer for each category all you need to do is add the following code:

The code above will look for footer-blogging.php to replace the default footer file if the category is Blogging.

Add post shortcodes to WordPress pages

Displaying Recent Posts in WordPress Using Shortcode

Adding recent posts to a WordPress sidebar is fairly easy, but what if you wanted to show recent posts inside a WordPress post or page? The easiest way to display recent posts in WordPress posts and pages is by using shortcodes.

You’d begin by installing and activating the Display Posts Shortcode plugin. It works out of the box and there are no settings you need to configure.

Simply edit a post or page where you want to display your recent posts. Next, use the shortcode [display-posts] with your own parameters inside the post. The plugin offers a whole range of parameters that you can use with the shortcode. Here are some examples:

Display 5 recent posts with thumbnails and excerpt

1 [display-posts posts_per_page="5" image_size="thumbnail" include_excerpt="true"]

Display recent pages instead of posts

1 [display-posts posts_per_page="5" post_type="page"]

Change the order to title instead of date.

1 [display-posts posts_per_page="5" orderby="title"]

Display recent pages under a specific parent page.

1 [display-posts posts_per_page="5" post_type="page" post_parent="5"]

For a full list of parameters visit the plugin’s documentation.

You can also use these shortcodes inside a text widget, but first you will need to enable shortcodes in your text widgets by adding this code to your theme’s functions.php file or a site specific plugin.

1 add_filter('widget_text', 'do_shortcode');


Watch the video about displaying recent posts on pages and posts inWordpress:

Add new Posts through Email

Add a new Post by Email

Post by Email is a way of publishing posts on your blog using your email. Any email client can be used to send the email, allowing you to publish quickly and easily from devices such as cell phones if you don’t have the WordPress mobile app installed.

The internal WordPress ‘post by email’ has been disabled and will be removed from WordPress. It is recommended to add this useful functionality by installing the widely used Jet pack plugin.

Once Jet pack installed and activated, you need to switch on the Post by Email module:

You can do this in a few easy steps:

  1. Go to Jetpack > Settings > Writing in your dashboard, and open the Post By Email card.
  2. Click on the toggle to activate the module.
  3. Copy the special email address that was generated for you.

Need more detail? Read on or click directly to the section you want to see.

Sending Emails

Once you have your Post by Email address, sending an email is simple:

Post By Email - mail example

The email subject is used as your post’s title. The body is the post’s contents. Please note you can only post to one recipient at a time.

Mail Formatting

Your email can be plain text or formatted. As much formatting as possible will be retained, although the Post by Email system will strip unnecessary HTML tags so that your email is displayed correctly. Note that you will need to use an email client that supports rich text or HTML formatting in order to make use of this feature. Most website based clients (Hotmail, Gmail) do support this, as do most desktop clients (Outlook, Mail). You may need to switch your client into rich text or formatted mode.


Post by email will automatically remove any email signatures that match the standard signature block pattern:


(that is, dash dash space)

It will also remove anything after a <hr/> HTML tag and attempts to clean up cellphone network signatures.

If your email system attaches a signature that does not match any of these patterns then you can manually tell Post by Email to stop including text by adding the special [end] shortcode on its own line with a blank line above it. Anything after this will be removed from your post. If your cellphone network is adding a signature and you want us to remove it, then let us know the details and we’ll look into it.


Image attachments will be included in your published post as follows:

  • Single images will be displayed inline (a single image is defined as an image without an image immediately following it).
  • Multiple images will be displayed as a gallery.

Multiple galleries and single images are allowed in the same post. Note that using the [nogallery] shortcode will disable all galleries.


Special shortcodes can be embedded in your email to configure various aspects of the published post:

  • [category x,y,z]
  • [excerpt]some excerpt[/excerpt]
  • [tags x,y,z]
  • [delay +1 hour]
  • [comments on | off]
  • [status publish | pending | draft | private]
  • [slug some-url-name]
  • [title Your post title]
  • [end] – everything after this shortcode is ignored (i.e. signatures). Make sure it’s on its own line with a blank line above it.
  • This slideshow requires JavaScript.

     – replaces the auto-gallery with a slideshow
  • [nogallery] – disables the auto-gallery and displays all images inline
  • [more] – more tag
  • [nextpage] – pagination
  • [publicize off|yahoo|twitter|facebook] – change Publicize options (see below)
  • [poll]question and answers[/poll] – insert a Polldaddy poll into your post (see below)

Shortcodes can be included anywhere in the body of your email and must be in lowercase. There should be no spaces between the left square braket and the shortcode content.

Specifying the Category

The category shortcode will match the category-slug specified. For example:

[category holidays,main-dishes]

Will match the categories “Holiday” (slug=holidays) and “Main Dishes” (slug=”main-dishes”). Note that categories must already exist on your blog for you to use the slug. If you want to add a new category, just type the new category name in the shortcode along with any other category-slugs. Spaces between the commas are not important.

Specifying Tags

Any number of tags can be added to your post, each separated by a comma:

[tags one potato, two potato, three potato, more]

This will add four tags: “one potato”, “two potato”, “three potato”, and “more”. Note that your tags do not need to exist elsewhere in your blog and new tags will be created automatically.

Changing your Publicize settings

Jetpack’s Publicize lets you notify other web services about your posts. With the [publicize] shortcode you can control this from emails. Note that your Publicize settings must have been previously configured for these shortcodes to work. Also, if you have already configured Publicize and don’t include these shortcodes in your post, it will be Publicized to all of your connected Publicize networks.

[publicize off] – disable all Publicize notifications

[publicize twitter] – only send a notification to Twitter

[publicize twitter]my new post[/publicize] – only send a notification to Twitter and set the Twitter status to my new post

[publicize twitter facebook] – Sends a notification specifically to both Facebook and Twitter only.

Note that if you use more than one [publicize] shortcode in your post (for example, both [publicize twitter] and [publicize facebook]), only the second shortcode will be used (in this case, [publicize facebook]). If you want to Publicize to only those two services such as in this example, you need to use a combined shortcode, like [publicize twitter facebook].

Inserting a Polldaddy poll

You must first have created or imported a Polldaddy account into before using this shortcode. Once setup you can insert a poll in an email as follows:


What is the worst movie of the decade?

* The Love Guru

* Fool’s Gold


Note how the poll question is added after the [poll] shortcode, and each answer is on a new line and starts with an asterisk. The poll must be finished with [/poll].

You can configure your poll by adding extra details to the [poll] shortcode:

  • type="single | multi | 2 | 3" – how many times a vote may be registered (single by default)
  • style="manga medium" – the style of the poll, as taken from the Polldaddy polls page.
  • other="yes | no" – allow an ‘other’ response (noby default)

For example, to create a poll with the wide ‘manga’ style and allow up to three responses (including an ‘other’ response):

[poll style="manga wide" other="yes" type="3"]

What is the worst movie of the decade?

* The Love Guru

* Fool’s Gold


Delaying Your Post

The delay shortcode will accept any time allowed by PHP’s strtotime. For example, you can:

[delay +1 hour]

[delay +2 days]

Providing a post title

The title of your published post is usually taken from the subject line of your email. In some instances, such as when sending an email from some cell phones or via a MMS-Email gateway, you may not be able to provide a subject. In this instance, you can set your post title directly inside the email:

[title My Fancy Post]

Changing your post status

Sometimes you may want your post to be private, or to be reviewed by yourself or someone else at a later date before being published. To do this, you can use the [status] shortcode to set the post status.

[status private]

Example Email with Shortcodes

The following email will be published in two days’ time to the “WordPress” category, with tags “announcement” and “WordPress”:

Welcome to Post by Email, the easiest way to blog!

[tags announcement, WordPress]

[category WordPress]

[delay +2 days]