I’m using this nifty little plugin called Custom Post Type UI to add custom post types to my WordPress site and am having a little trouble working out the best way to apply a page template to my custom post types.
Does anyone know the best way to achieve this?
Any help is appreciated. Thanks in advance!
WordPress has a built-in template hierarchy that determines what template file will be loaded for a given type of post or page. If you have a look at the visual overview of the hierarchy, you’ll find that custom posts have their own specific entries. For example, if your custom post type is named book
, then a single post’s template will be single-book.php
if it exists, single.php
if it does not. (index.php
is the global fallback — a theme really only needs to contain style.css
and index.php
to function.)
Any desired template files (ie, single-{$posttype}.php
) should be added to your active theme.
References
- Post Types
- Template Hierarchy