Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

Create Custom Single Post Templates for Specific Posts or Sections in WordPress

Last updated on by
Special WordPress Hosting offer for WPBeginner Readers
Create Custom Single Post Templates for Specific Posts or Sections in WordPress

In one of our previous tutorials we shared how you can create a Custom Page in WordPress where we created a custom page template. But did you know that you can do that for single posts also? In this tutorial we will share how you can create a custom single post template for each specific post, specific author, or a specific category.

We recommend you have a basic knowledge of HTML and CSS with an understanding of how WordPress themes work before you try these tutorials.

Custom Single Post Template for Different Posts

This technique will let you create custom single post templates and you can select which template each post need to use as you are writing it. To accomplish this, you must download a plugin called Single Post Template and follow the directions below.

Then you will need to create a custom file which for the examples sake we will name customsinglepost.php. You can copy your normal single.php info and change the things that you want. Or you can create a completely different design if you so desire. But one thing you must make sure that you do is to add the following code at the top of the file that you create:

Single Post Template: [Descriptive Template Name]
Description: This part is optional, but helpful for describing the Post Template

Once you are done creating the custom template for single posts, save it among your other theme files in your theme directory. Considering you already have your plugin activated when you go in your WordPress admin panel to write a new post, you will see a drop down box that gives you an option to select which template you want for that specific post.

Single Post Template

Note: If you do not select any template, it automatically shows the default template. You can have as many templates as you like.

An Alternative plugin that does the same job is called Custom Post Template.

This method above is ideal for specific posts, but if you want to have a completely different template for specific category, then the method above can be automated with a few codes in your file. This will save you time from editing each post and selecting the specific template especially if you have a lot of posts already published in that category. The automated method was shared by Justin Tadlock, one of the very famous WordPress theme developer.

Custom Single Post Templates for Specific Category

To use a separate single post template for each category, you will need to add the following function in your functions.php:

* 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';


This code will tell the script to look for templates such as single-cat-uncategorized.php or single-cat-1.php within the /single folder. You must make sure that you save the files within the single folder that you will need to create in your theme directory.

Custom Single Post Template for Specific Author

Simply place this code in you functions.php and it will tell WordPress to look for templates such as single-author-admin.php or single-author-1.php and if it does find it in your /single folder.

* 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 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';

We can’t really specify how you must create your custom single post template because that is upto you and depends on what customization you want to make, but if you get stuck feel free to ask us any question. What we must emphasize is that you must save all these custom templates in a folder named /single that must be located in your themes directory.

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Your Real Name says:

    This plugin is not being updated for 2 years ! May be it will not be supported in the recent version of wordpress, maybe after 3.5+ . There is an alternative i use called “WP Post Type Template”. It will provide a dropdown field with template lists available in all post types and you can choose one for any post of any type.

  2. Ted says:

    Both plugins mentioned in this article are now out of date. Can you recommend a newer one for creating customised single post templates?


  3. Jason says:

    this will only work if single folder is placed in the parent theme, if the single folder is placed in the child theme, this won’t work… how to make it work in child theme? pls help..

  4. D says:

    aww man, I have been trying to figure this out for hours and when I add this Custom Single Post Templates for Specific Category code to functions.php, I get a syntax error. Wish I knew what I was doing wrong.

  5. Dashrath says:

    Its redirecting all other single posts to Home page now. Just the category posts for which I made a new file are going to that singles template.

  6. Umar says:

    Is possible to define taxonomy template to specific directory.

  7. WPBeginner Staff says:

    Simply name the template for your single custom post types like this single-{post_type}.php

    Let’s say you have a custom post type called movies then you would name the template file single-movies.php

    • Stefan Malic says:

      Yes, but the file has to be in the theme folder. You can’t do it from the plugin folder :/

    • Umar says:

      but want to specify taxonomy archive template.
      example : CATEGORY_PATH/{taxonomy}/category-{term->slug}.php

  8. Steffe Henriksen says:

    Great tutorial, but this does not seem to work if you have made a custom post type – any ideas on how to include it in CPT?

  9. Mustafa Faris says:

    Thank you,
    This is a great tutorial.
    It work perfectly for me

  10. Reto says:

    How can i add manualy, just a single post template, that i created to a specific single post-type.
    I mean as you do in this explenation “Custom Single Post Templates for Specific Category”, just not automated.
    I dont want the choice of the “custom post template” plugin,
    I just want have a certain template for a certain posttype.

    Thaks for answers

  11. Himanshu Goel says:

    Sir Thanks !
    You sorted out my half the tension via this. As i was having a theme with multiple color schemes and without generating much codes i can assign the css file to new templates.
    But the question is: What will happen if single post is posted under multiple categories i.e. 2 or more. will it show an error or will it work anonymously with any category or with the last slug or id detected.
    you can post here and mail me (in case i couldn’t find this page again)
    I really need to design my site with multiple color schemes as there are different parent categories to differentiate with others.
    Also, what will happen with sub-categories…

  12. John Shine says:

    you should add the flowing code at the end of the code so return default template file if there is not a custom template.
    else return TEMPLATEPATH . ‘/single.php’;

  13. Jeffrey says:

    Hi Samuel!
    Some great insight here! :) Hoping you can help me bring it to the next level…b/c I’m stumped on something. Here’s the scenario:
    -I have a feed of posts that when clicked from this feed, they open in an iframe by adding ?TB_iframe=true&width=1000&height=550″ class=”thickbox” to the link
    -Using your example of “Custom Single Post Templates for Specific Category” I am able to point them to a specific template I’ve created … all good
    -The issue is when a user encounters a post that utilizes that same category … when clicked it ALSO uses that new single-cat-temp.php :( And looks all wonky.

    Is there a way to isolate the function further to only kick in the use of the custom single when IS category && Coming from a specific page or in the iFrame?

  14. Samuel says:

    In both code blocks, there the last part that is missing (missing end brace):

    return $single;

    It is mentionned at the end of Justin’s article that you mentioned.

  15. Luit Krol says:

    I use the plugin Custom Post Templates to select a custom made template for my custom posts. How can I make this specific template the default for this custom post type without having to select it manually?

    thanks for your help


    • Editorial Staff says:

      You can save that template as single-$posttype.php, and it will be set as the default template for that custom post type.

  16. mark shirley says:

    Neither plugin works they strip the styling out of twenty eleven child theme. The first one doesnt even give you the pull down admin selector

    • Editorial Staff says:

      We are using the bundled version of the first plugin in Genesis, and it seems to work just fine on our site. The plugin itself should NOT strip out your styling. All this is doing is giving you the ability to pick a different single template. If you did not code the single template properly, you will see styles being stripped out.

      • Chris says:

        Hi there,

        The plugin didn’t work with the latest wp 3.4.1,
        do you know how to fix it?

        The template is not showing when I create post.

        • Editorial Staff says:

          Did you try both Custom Post Template and Single Post Template?? At least one of them should work. We are using Single Post Template’s variation that comes bundled with the Genesis Theme framework.

  17. guest says:

    This plugin does not work with 3.3.1 unfortunately

  18. CapitalH_Press says:

    I used this code in my file that I created and named it

    <?php/*Single Post Template: [Descriptive Template Name]Description: This part is optional, but helpful for describing the Post Template*/?>

    Then without adding the plugin or setting any function my portfolio custom posts are using this file as their single file template, I think in WP 3.3 we no longer need plugins like that.

  19. frankandjen says:

    Is there anyway to get this to work with custom post type templates?


  20. marktastic says:

    My apologies if this is a simplistic question, but I just want to make a new category for posts and want all of that category to have the same custom template.

    I create the custom.php and throw it in the theme file as shown. I activate the plug in.

    Do I have to add all of the above listed code if all I care about is that one specific category? Or is there a shortcut?

    Thanks for your article!!

  21. Rotten Elf says:

    WOW!!!!!!!!!!! I just came up with an idea that required this, and in looking in the wp-admin panel, I noticed that custom post templates weren’t available, but I thought “wait…I can’t be the first person to need this, I’ll google it” lo and behold, you have the solution. Thank you WPBeginner (and everyone else in the WP community that shares information and techniques). I seriously needed this little tut on creating custom post templates!

    This opens up so many doors for me… many doors.

  22. jeff campagna says:

    Hey! Great Article!

    What if the element you want to change is not in the single.php file but in the loop.php file? The loop calls the post thumbnail to appear before the post title. But I want, for a specific category, to remove that thumbnail from the loop…

    Hopefully I am making myself clear.
    Thanks so much for this!

    • Editorial Staff says:

      If it is just for one category, then you can always create a category-slug.php file which will override your current settings :)

  23. Peter says:

    Hi there,

    I was just wondering if it’s possible to use the template for the latest post on the front page, where I only show one post.

    • Editorial Staff says:

      If you just want to show one post on the homepage, utilize the custom homepage article that we have shared in our site.

      Run a wp_query for the loop to show the first post only, and style it the way you want.

      • Peter says:

        Thanks for the quick answer :)

        What I meant was, when I use a different post template for all my blog posts, how do I make sure that when only showing one blog post on the home page, that blog post will use, say, single-custom.php, instead of index.php or home.php?

        I could just paste the content of single-custom.php in index.php or home.php, however, I would have to do that every time I create a new blog post.

        • Peter says:

          To elaborate, I use a custom header for each blog post, e.g.


          In my index.php file I just have


          Also, I put in some extra elements before and after the loop.

 does what I need — shows only the latest post with a custom layout. Just can’t figure out how to do it.

        • Editorial Staff says:

          You might have to store the template in custom-field and then pull it that way. You can also utilize the new Post Formats to display it that way. Maybe the method shared in this article is not the best method…

          Custom Taxonomy may also be another solution…

  24. Travis says:


    In “Custom Single Post Template for Specific Author” you may want to copy the original single.php to the single template path then add:

    elseif(file_exists(SINGLE_PATH . ‘/single.php’))
    return SINGLE_PATH . ‘/single.php’;

    at the end of the code so if there is not a template set up for an author, it will fallback to a template, rather than the homepage.

  25. Travis says:


    I am trying to use the “Single Post Template” plugin and the “Custom Single Post Template for Specific Author” method described above.

    How can I make WordPress check if there is a “Single Post Template” before checking for an Author template?

    The special single post templates I have set up need to be the first priority.


  26. Javier says:

    Hi there, thanks for the post. Just one thing, you are missing the
    “return $single;” statement at the end of your code.

    I now it may seem that it is not needed but I will recommend use it as it may do behave randomly if not. (I got in troubles myself using the “one room” template becouse I got no comments section in the default single.php when not using “return $single.php;”)

    Cheers for sahring!!


    • Wes says:

      Thanks for the info… a filter like that should always return its input value if there were no modifications. And thanks to the original author for sharing! Works great.

  27. kel says:

    The Art Direction plugin takes a slightly different approach. Unfortunately it hasn’t seen much updating lately.

  28. Jason Pelker says:

    Regarding the specific category template…

    Is there a way to use a default file (i.e. single.php) for when there is no single-cat-1.php file?

    If there isn’t an appropriate single-cat-1.php file (or whichever category is being called), the functions.php code above then uses the index.php file to call the loop.

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.