How to Create Custom Single Post Templates in WordPress

This post was last updated on August 3rd, 2021 at 11:21 pm

Are you looking to create a unique single-post template in WordPress? Customized Single post templates to allow you different layouts and styles for your posts. A lot of WordPress themes include a variety of page templates. However, you can also make your own.

In this informative guide, we will be showing you how to create customized single-post templates. WordPress offers many options for making customized single-post templates.

Why do You Require Customized Single Post Template

Many times , you might want a another design for specific posts. For example, featured articles and stories within a category may require a different layout.

You will need a WordPress template that is unique for each post.

WordPress default uses a single template for all posts based upon the WordPress template hierarchy. Each theme comes with a single.php template that will be used for single posts.

Read Also: Read our detailed guide on create custom homepage in WordPress. 

There may be additional templates or layout options that are available with certain themes.

It’s very similar to creating a customized page template. You can also use page templates in most WordPress themes to edit pages.

choose page template

Let’s look at the steps to create single post templates using WordPress. We’ll demonstrate multiple ways to create single post templates in WordPress so you can choose which one works best for your needs.

Create a single WordPress post template using The Block Editor

This method isn’t able to create a template for your post and has limited flexibility. This is the simplest mean you can save single article layouts that you can use again later.

WordPress default blocks editor comes with an integrated feature that allows for saving and reusing of blocks. One example of a reusable block is the Group block.

The group block allows you to combine multiple blocks and complete post layouts into one block. This group block can then be saved and reused in other posts.

Must Read: Read our detailed guide on Hostinger hosting. 

Let’s see how the group block can be used for saving your custom post templates.

First, you will need to create a brand new WordPress post. In the content area, add a group block. 

addgroupblock

You can add blocks to group blocks to create a single-post layout. You can add all the blocks you need, including columns and media and text, as well as cover images.

addblockstogroup

Once you are happy with the layout, move your mouse to select the group blocks. Click on the three dots symbol to open the menu and  select the option Add to Reusable Block.

addreusableblock

Next, give the block a name and click the Save button. WordPress would now store both your block and all blocks in the group block.

Next, edit or create new posts for your website. To locate your saved block, click on the Add New Block button located at the bottom.

reuseblock

Add the block in your post to load the whole group block and all the settings and blocks you saved.

This will permit to store your customized layouts. This does not permit for you to modify the mean your theme handles individual blog posts.

You may want to have more flexibility, then keep reading.

Create Customized WordPress Single Post Template with Beaver Builder

Beaver Builder is the best way to create your single post template. It is the best WordPress plugin for page builders. Post templates can be created without the need to modify or code your WordPress theme.

You first need to install and activate Beaver Builder. You will need to activate your Beaver Builder license by visiting the Settings >> Beaver Builder page.

bblicense

These details can be found on the Beaver Builder website. Beaver Builder is by default enabled for Pages in WordPress. It would also required to be allows for posts.

You can do this by going to the Post Types tab in Settings >> Beaver Builder page. To confirm, check the box next to Posts. Save your changes by clicking the Save Post Types button.

bbposttypes

Once everything is in place, let’s make a custom post template. Simply create a post in WordPress. Then, on the post edit screen, click on the “Launch Beaver Builder” button.

launchbb

This will bring up the Beaver Builder interface, which displays a live preview for your website. You can add rows and modules to your layout by clicking the Add button located in the top-right corner of the screen.

A template can be used as a starting point. You can even choose a blank template, so you have a clean slate from which to start.

bbselecttemplate

You can edit a template by simply clicking and pointing. You can also add columns to your template and fill them up with modules or elements.

bbmodules

Play around with the settings and experiment with different modules. After you’ve created the template and it is time for it to be saved.

Beaver Builder allows users to save their layouts as templates and reuse them in other posts. Just click the menu at the top-right of the screen and choose Save Template.

bbsavecustomtemplate

The template name is required. To save your template, click on the Save button.

savecustomtemplatebb

Let’s now look at how to use this template for creating posts.

You can edit an existing post or create a new one. The Beaver Builder will then launch to edit the post.

Must Read: Read our detailed guide on GeneratePress Theme. 

Next, click the Add button at the top right of the screen. After that, switch to the Templates tab. Next, click on the Add button at the top right corner of your screen and then switch to the Templates tab.

loadcustomtemplate
You will need to choose ‘Saved Templates” from the Group drop down menu.

Beaver Builder will now load the saved layout. You can then add content to your new article.

Customized Single Post Layouts using Theme Settings

Many WordPress themes include built-in settings for customizing the appearance of single posts.

If your theme supports these settings, you will be able to find them in the post edit screen. Depending on the theme you may choose, there may be different options available.

This is one example of the Astra theme’s customization options for editing a single blog post.

astrasettings

You can use these options to alter sidebars, hide headings, title, and menus.

However, most of the top WordPress themes have ready-to-use templates that you can utilize.

If your theme contains single post templates, you can find them under the post attributes tab when editing a blog post.

fullwidthtemplate

These templates have complete layouts you can use.

Manually Make Customized WordPress Single Post templates

This method requires that you edit the theme files, copy-paste code, and, optionally, add custom CSS.

Firstly, you need to start  and text editor  or note pad on your computer and copy the given code below:

<?php
/*
* Template Name: Featured Article
* Template Post Type: post, page, product
*/
get_header();
?>

This code creates a new template called Featured Article and makes it accessible to all kind of article, page, and item post types.

You can save the file as wpb-single-post.php on your desktop. Next, upload the file using an FTP client to your WordPress theme folder.

You will then be able to log into your WordPress admin area to create or modify a post. Scroll down to the post edit screen, and you’ll see the new post attributes meta box. You might have this choice to choose the template.

customposttemplate

You’ll see your Featured article custom template there.

The template is currently blank, so it can be selected to display a white background.

Let’s get started.

To use it to start copy the code from your theme’s single.php

After the get_header() line, open single.php and copy it.

This code should be pasted at the end of your wpb-single-post.php. This file can be saved and uploaded to your server.

This template will look exactly the same as your existing single-post template.  You can now make modifications to your custom single-post template.

You can also add custom CSS classes to remove sidebars and create full-width templates.

Make Customized Single Post Templates with Category

A custom template can be created for each category.  A custom template can be created for a single post based on a specific category, such as posts about photography or travel. These are just a few of the ways you can accomplish this. First, add the code to your theme’s function.php file or your site related plugins. 

/*
* Define a constant path to our single template folder
*/
define(SINGLE_PATH, TEMPLATEPATH . ‘/single’);
/**
* Filter the single_template with our custom function
*/
add_filter(‘single_template’, ‘my_single_template’);
/**
* Single template function which will choose our template
*/
function my_single_template($single) {
global $wp_query, $post;
/**
* Checks for single template by category
* Check by category slug and ID
*/
foreach((array)get_the_category() as $cat) :
if(file_exists(SINGLE_PATH . ‘/single-cat-‘ . $cat->slug . ‘.php’))
return SINGLE_PATH . ‘/single-cat-‘ . $cat->slug . ‘.php’;
elseif(file_exists(SINGLE_PATH . ‘/single-cat-‘ . $cat->term_id . ‘.php’))
return SINGLE_PATH . ‘/single-cat-‘ . $cat->term_id . ‘.php’;
endforeach;
}

This code first checks if WordPress requests only one post. If it is, the code tells WordPress that it has found the template in the /single/ folder.

Now, you will need to create template files using this code. Connect to WordPress Hosting using FTP Client or File Manager in the cPanel.

Proceed to  /wp_content/themes/your_theme_folder/ In your current theme folder, create a new folder named single.

Now you require to start the above folder and make a new file inside it. Go ahead and give the title this file single-cat-{category-slug}. Displace {category-slug} with your original category slug.

You will create single-cat.php files if your category is ‘News’. Create a single template cat-travel-tips.php if you have a category called “Travel Tips”.

categorysingleposts

These templates files will be empty. To get started, copy the contents from your theme folder’s single.php file and paste it inside each one of these templates.

You can make any changes to these templates by clicking on the link.

You can now visit your site to browse a post. This will utilize the template that you make to place the above post in the correct category.

Let’s assume you have a blog post in the News category and a Travel Tips category. WordPress will show the news template because it is alphabetical first.

WordPress would utilize the pre-made single.php template if you haven’t created a template for a category to file your post.

Create a single template for specific author

Let’s say you need posts composed  by a certain author to show different on your website. The same techniques we used to create categories can also be used.

Firstly , you’would required to insert the code to your theme’s functions.php or a site-specific plugin.

/**
* Define a constant path to our single template folder
*/
define(SINGLE_PATH, TEMPLATEPATH . ‘/single’);
/**
* Filter the single_template with our custom function
*/
add_filter(‘single_template’, ‘my_single_author_template’);
/**
* Single template function which will choose our template
*/
function my_single_author_template($single) {
global $wp_query, $post;
/**
* Checks for single template by author
* Check by user nicename and ID
*/
$curauth = get_userdata($wp_query->post->post_author);
if(file_exists(SINGLE_PATH . ‘/single-author-‘ . $curauth->user_nicename . ‘.php’))
return SINGLE_PATH . ‘/single-author-‘ . $curauth->user_nicename . ‘.php’;

elseif(file_exists(SINGLE_PATH . ‘/single-author-‘ . $curauth->ID . ‘.php’))
return SINGLE_PATH . ‘/single-author-‘ . $curauth->ID . ‘.php’;
}

Next, connect your website to FTP using File Manager in cPanel. After that, go to /wp-content/themes/your theme-folder/.

If you don’t have a folder called “single” inside your computer, let’s start creating it.

In this folder, create a template by entering the author’s username into the template name. For example, single-author-.

Must Read: Read our detailed guide on SEMrush best SEO tools. 

This template will not be used. You may replicate the words of the single.php template from your theme and use it as a base.

You can now go to your site and see the post created by this author. This concludes our article on creating single WordPress post templates.

We hope you found this article helpful in learning how to create single-post templates in WordPress.

Leave a comment