Page Templates For Custom Post Types In WordPress

When first creating a custom page template for your new custom post type (CPT), you may be disappointed to find No templates exist for this post type in the template dropdown in the post edit screen. No fear! You are closer than you think.

Now, this tutorial assumes you have already created a template file (page-cpt.php) and added to your theme. If you don't, a quick Google for "how to create custom page templates in WordPress" will lead you in the right direction. That said, the key here is to ensure you are specifying the correct content type in your template definition. What is a template definition? What I'm referring to is that little php comment that's included at the top of a WordPress page template file.

This tiny little php comment is used by WordPress much like the css comment that defines your theme in style.css. It's easy to gloss over this template definition and just assume it's syntax is "Page Template: nameOfTemplate". While you wouldn't be far off, you'd be off enough to not be seeing what you want!

So, the common template types are:

<code>
Page Template: ...,
Post Template: ..., and
cptName Template: ...
</code>

For example, here is a screenshot from a Tutorials Post Type I used to make this blog.

WordPress Custom Post Type Template Definition

The page template definition you see above is as important to get right as it is to use the correct file naming convention of the .php document your running this script from within. If either of them are not in the proper format, it's a deal breaker and you will not be able to select your template or it will not have the intended effect . So to recap, if you are creating a page template, use the word "Page", if creating a post template, use the word "Post", and by the same logic, if you are creating a custom post type page template, use the singular form of the word for "YourCptName"! It's just that simple.

Things to keep in mind:

1) Not all themes follow the standard WordPress API and therefore the naming convention of the template file may differ. For example, if you are using the Genesis framework, the template file name will be cpt-page.php instead of page-cpt.php. Straight forward but easilly overlooked.

2) The Hybrid framework sometimes also does its own thing and may use different naming conventions for things like templates and hooks. Don't be afraid to experiment!

3) Some other important point goes here..

https://wordpress.org/support/topic/theme-hybrid-no-templates-exist-for-this-post-type

<?php
/**
 * Page Template: Some Page Template
 *
 */
 
// VS
 
/**
 * Post Template: Post Template Name
 *
 */
 
// VS
 
/**
 * NameOfCustomPostType Template: CPT Template Name
 *
 */
 
?>

Once you do add this type of definition to your php template you can simply upload it into your WordPress theme directory and then you'll see it in your Page Template widget area like below.
Tutorials post type dropdown menu wordpress admin



Recent Tutorials

Page Templates For Custom Post Types In WordPress

When first creating a custom page template for your new custom post type (CPT), you...more..

Essential SEO Techniques

Search Engine Optimization Recitals It is the goal of every website to...more..

Automate Your Tasks With GulpJS

This tutorial is a little more on the advanced side and assumes basic knowledge of...more..

Setting Up SSH Keys

By developing from the command line you remain more focused on the task at hand...more..

Contact Us

  • This field is for validation purposes and should be left unchanged.