Create a custom template for a custom post type in WordPress
How to create your own single template (single-{slug}.php) for a custom post type in WordPress and display only what you need: title, image and content.
WordPress
The theme decides how a single custom post type entry looks by default. In this tutorial we show how to create your own template (view) for a custom post type in WordPress, so you control exactly what is displayed and how. At the end, the page has a simple layout: header, entry content, footer.
A separate template lets us add CSS only for this post type and write custom functions without affecting the rest of the site.
The screenshots show the Polish admin interface; field names in the code stay as shown.
What we need
- The Custom Post Type UI (CPT UI) plugin. It is free in the WordPress plugin directory and creates a custom post type without writing code.
- Access to the theme files (via FTP, SSH, or a code editor in a local environment).
- Basic knowledge of PHP and the WordPress loop.

Step 1. Create the custom post type
After installing the plugin, we open Add/Edit Post Types and add a new post type. It can be any repeatable set of content the site needs. In our example it is a set of guides with a featured image, a title and a description.

We scroll to the bottom of the form and select the options we need: title, editor (description) and featured image. We confirm with the Add Post Type button.

A new Poradniki (Guides) tab appears in the WordPress admin menu.
Step 2. Add sample entries
We add a few guides and then display a single entry on the site.

In the example we added three guides with different titles, descriptions and images.
The layout of the Poradnik (Guide) custom post type is currently set by the theme we use: Twenty Twenty.

Step 3. Create the template file
Suppose we do not like the default view. We do not want the bottom navigation, the author or the date. To change this for one post type only, we create a separate PHP file that handles it.
We go to the WordPress themes directory (wp-content/themes) and choose our theme. In the example it is twentytwenty.


In the theme directory we look for single.php or, as in Twenty Twenty, singular.php, and make a copy of it. Which of these files is used depends on the theme. Usually one of them renders the single entry view.
We rename the copy to single-{slug}.php, where {slug} is the post type slug entered in the first field of the CPT UI form. In our case it is single-poradnik.php. WordPress picks this file automatically for entries of this type, according to the template hierarchy.

Note: changes in a parent theme are lost when the theme is updated. On a production site, it is better to add the file to a child theme.
Step 4. Edit the template
We open single-poradnik.php. It contains the code copied from singular.php. This is how the file looks in the Twenty Twenty theme:
<?php
/**
* The template for displaying single posts and pages.
*/
get_header();
?>
<main id="site-content" role="main">
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
get_template_part( 'template-parts/content', get_post_type() );
}
}
?>
</main><!-- #site-content -->
<?php get_template_part( 'template-parts/footer-menus-widgets' ); ?>
<?php get_footer(); ?>
We want to remove the bottom section with the latest entries and show only the guide content together with the site header and footer. We replace the code with the following:
<?php get_header(); ?>
<main id="site-content" role="main">
<?php while ( have_posts() ) : the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php the_post_thumbnail( 'full' ); ?>
</article>
<?php endwhile; ?>
</main><!-- #site-content -->
<?php get_footer(); ?>
This gives the layout we wanted: header, custom post type content, footer.

Common problems
- WordPress still uses the old view: check that the file name is exactly
single-{slug}.phpand that the slug matches the post type slug in CPT UI. Re-saving the permalink settings (Settings, Permalinks) can also help. - Blank page:
get_header()or thewhile ( have_posts() )loop withthe_post()is missing. - No image or description: check that the post type settings enable the featured image and the editor (the
thumbnailandeditorsupports).
Summary
Creating a template for a custom post type is simple, but the details matter:
- Name the post type simply, without special characters. The slug becomes part of the template file name.
- Plan the structure of the custom post type and the fields you need to display an entry correctly. Custom field types that CPT UI does not offer can be added with the Advanced Custom Fields plugin (we describe it in Advanced Custom Fields: custom field types in WordPress).
- Output the fields inside the
while ( have_posts() ) : the_post();loop. Thanks tothe_post(), functions such asthe_title(),the_content()andthe_post_thumbnail()work on the current entry.