by in Developer Notes

I had what seems to be a common problem applying a custom template to a custom post type in WordPress.

First, I up the post type with custom fields using Custom Field Suite and Custom Post Type UI.  I initially had the a custom template set up and working properly, pulling in the corresponding custom fields that I created for a standard “page” post type.   However, when I attempted went to select the template for use with a custom post type, the drop down to select the custom template didn’t show up in the attributes tab like it did on the pages. Come to find out that WordPress natively doesn’t allow for templates in posts. Ugh!

After looking around and trying several solutions I found the Custom Post Template plugin.

To Install :

  • Download the plugin, it will arrive as a zip file
  • Unzip it
  • Upload custom-post-template directory to your WordPress Plugin directory
  • Go to the plugin management page and enable the plugin
  • Upload your post template files (see below), and choose them through the new menu

Be sure to change the template name in the header of your template:

<?php /* Template Name Posts: Inforest 1 */ ?>

If using a Custom Post Type add the code below to your Functions file and change $post_types[] = ‘movie’; to the name of the post type you are using:

 * Hooks the WP cpt_post_types filter 
 * @param array $post_types An array of post type names that the templates be used by
 * @return array The array of post type names that the templates be used by
function my_cpt_post_types( $post_types ) {
    $post_types[] = 'movie';
    $post_types[] = 'actor';
    return $post_types;
add_filter( 'cpt_post_types', 'my_cpt_post_types' );

Leave a Reply

You must be logged in to post a comment.

About Leon Rainbow

Leon is primary lead for Inforest Communications graphic and Web design services. He has over ten years experience in Web design and development and is proficient working with open­source CMS systems. He holds an associates degree in Computer Graphics from Mercer County Community College. Leon Rainbow is also a well known artist in Mercer County who creatively combines graffiti, street art and other artistic forms into innovative projects and events. He reaches out to wide audience, from galleries to the walls of inner cities. Leon curates two annual art festivals in New Jersey for area painters and the community as well as dedicating his civic duty to teaching after­school art programs in Trenton and Princeton, NJ.