Publié le Mis à jour le 18 min de lecture

Have you ever heard of a custom post type? Even if you’re new to WordPress, it’s a term you’ve probably come across. 

It has to be said that this is one of WordPress’s most powerful tools. And yet… Natively, the CMS (Content Management System) doesn’t even offer it to its users!

Probably because a minimum amount of technical knowledge is required to use it. 

Once properly mastered, this tool, often essential for many websites, opens up a world of possibilities. 

Flexible and scalable, a custom content type will help you organize and structure your content much more precisely than with a post, for example.

Want to know how to make the most of it on your WordPress site? You’re in the right place. 

By the end of your reading, you’ll be able to create a custom post type with and without a plugin, thanks to all our detailed step-by-step advice. 

What is a custom post type?

A custom post type is a WordPress feature that allows users to categorize and manage their content by configuring it themselves. It can be created using a dedicated plugin or PHP code. 

Introduced with the release of WordPress version 3.0 (2010), custom post types (CPT for short) are not included natively in every new WordPress installation. It’s up to you to create them, if needed. 

This is notably what differentiates them from the 7 content types present by default on every WordPress site, such as:

  • posts; 
  • pages;
  • attached files (attachments), i.e. your media (images, videos, PDFs, etc.); 
  • revisions, i.e. backups of your content (posts & pages);
  • navigation menus;
  • custom CSS;
  • changesets made in the Customization Tool (called the Customizer in English).

Like other default content types (e.g., posts and pages), custom post types in WordPress appear in the sidebar of your admin interface once they have been created. 

You can even assign your own taxonomies and custom fields to organize them even more precisely.

In fact, many well-known plugins use their own custom post types in WordPress. This is the case, for example, with the famous WooCommerce, which allows you to turn your WordPress site into an online store.

The e-commerce plugin offers, for example, a CPT called “Products”:

The Products custom post type created by the WooCommerce plugin in WordPress.

Why create a custom post type in WordPress?

Generally speaking, custom post types in WordPress allow you to better organize your site’s content and structure it.

In detail, using them offers several notable advantages: 

  • you gain flexibility, since you can customize each custom content type according to your needs; 
  • your content becomes better organized because you can split it into different categories; 
  • you improve the user experience (UX). If your content is better structured, it is easier to find and browse. This creates less friction and increases your chances of keeping visitors on your site in order to encourage them to complete the action of your choice (purchase, file download, form submission, etc.); 
  • you are not limited in the number of CPTs you want to create. You can create them without limits; 
  • you can use custom post types to categorize all types of content: products, films, recipes, testimonials, portfolios, etc.;
  • you can create specific page templates for each custom post type, giving you total control over the presentation and style of each content type.

When should you use a custom post type on your WordPress site?

The different possible use cases

Although custom post types offer many advantages, that doesn’t mean you should rush to create them!

Do you think a CPT is needed on your WordPress site and are you hesitating to get started? We recommend creating a custom post type in WordPress if: 

  • the different default content types offered by WordPress (posts and pages) do not allow you to structure your content the way you want; 
  • you want the appearance of new content to be different from the content types already present on your site; 
  • you need additional fields to organize your content. For example, if you run a cooking blog, you may want to list your recipes by ingredients, difficulty, cooking time, etc.;
  • the content you want to create does not match its “traditional” use on WordPress. For example, a post is used to create content for your blog, content that is likely to be updated. A page is used to display static content (also called “cold” content). 

Concrete examples of using custom post types on WordPress

To make things more concrete, let’s take a specific example. Imagine you are in charge of managing a blog dedicated to cinema. 

To make everything clearer and easier to digest, you want to classify the films you have reviewed according to different criteria: 

  • actor; 
  • duration; 
  • genre; 
  • release date; 
  • rating, etc.

For each blog post corresponding to a film review, you can of course assign it different categories and tags. 

However, these last two taxonomies have limitations:

  • you may quickly end up with many categories on your site, making the organization less clear for you, your site users, and your visitors; 
  • the categories and tags of your blog posts are not the most logical way to classify your content. Imagine the number of categories you will have to create just to differentiate series by type (action, horror, drama, comedy, etc.)!

In this case, creating a custom post type will make much more sense. And you can even create them to display whatever you want:

  • events;
  • creations from your portfolio; 
  • products for your online store; 
  • testimonials; 
  • recipes; 
  • books; 
  • films; 
  • videos, etc.

In addition, each custom post type can of course contain its own custom fields. For example, the “Books” CPT can contain fields for the author, publisher, year of publication, number of pages, etc.

After the theoretical side, it’s time for practice. You will now discover how to create your own custom post types on WordPress. 

What prerequisites are needed before creating a CPT?

As we explained above, creating a custom content type can be done via a plugin or with code. 

We will present both methods to you just below. Whichever one you use, we recommend that you first apply the following best practices: 

  • back up your site (files + database) before any technical operation. To do this, use a plugin like UpdraftPlus, or a maintenance tool like WP Umbrella. In case of a problem, you will be able to easily restore your site in just a few clicks; 
  • if possible, create your custom post type in a test environment first before moving it to production (on your live site).
    Once again, this helps protect you in the event of a technical error. To run your tests with complete peace of mind, work locally, for example, with the Local tool. You can also rely on the WordPress Playground tool, which lets you simulate a WordPress environment in your web browser:
The WordPress Playground tool lets you simulate a WordPress environment and create custom post types.
The WordPress Playground tool

How to create a custom post type in WordPress with a plugin?

Let’s now look at the first method for creating a custom post type in WordPress. It consists of using a plugin. 

This is the simplest and fastest way to get started. It is particularly suitable for beginners and non-technical users – among others – because it does not involve handling code. 

In the official WordPress plugin directory, several free custom post type plugins are available:

For the purposes of this test, we chose Custom Post Type UI for several reasons: 

  • it is the most popular on the subject (1 million+ active installations); 
  • it is easy to get to grips with and use; 
  • its settings are available in French; 
  • it is very highly rated by its users; 
  • it is frequently updated; 
  • it is developed and maintained by an agency specializing in WordPress (WebDevStudios), which has an excellent reputation within the ecosystem.
Screenshot of the Custom Post Type UI plugin on WordPress.

Here is how to use the Custom Post Type UI plugin step by step.

Step 1: Install and activate the Custom Post Type UI plugin

To get started, go to the Plugins > Add New Plugin menu.

In the search bar, type “custom post type ui”, then install AND activate the plugin:

Installing the Custom Post Type UI plugin in the WordPress admin area.

You will then have a new… custom post type called “CPT UI” in the sidebar of your admin interface.

This is where you access the plugin’s settings menus:

The WordPress CPT UI settings menu.

Step 2: Create a custom post type

Next, click the “Add/Edit Post Types” submenu to design your first custom post type. For this example, we will create a CPT called “Movies”. 

Default configuration of your WordPress custom post type

At the top of the page, you will find a box called “Default configuration”. You are prompted to fill in the following elements: 

  • Post type slug. This is the part of the URL that will contain the name of your CPT. Here, enter “films” in lowercase. Do not use hyphens, underscores, or other special characters; 
  • Plural label (Films); 
  • Singular label (films); 
  • Auto-populate labels. If you click the “Populate additional labels based on chosen labels” link, Custom Post Type UI will generate the label names itself. This saves you a little time, but the translation is not perfect. We therefore recommend that, after clicking the link, you manually edit each label.
Default configuration of a custom post type with the Custom Post Type UI plugin.

Customizing labels

The “Additional Labels” box contains around thirty labels whose wording you can customize.

The translation of the CPT name that will appear in our admin sidebar is not suitable (“My Films”). We choose to rename it more simply as “Films”. 

Browse the list of labels and modify the ones you want.

Customizing labels with the Custom Post Type UI plugin.

Custom content type settings in WordPress

In the next box, you will find a whole series of settings on a single page. The default settings will do the job, but you can still make a few adjustments if you wish. Here are a few pointers to help you: 

  • the “Menu position” option allows you to choose the location of your custom post type in your admin sidebar. You can move it up or down by choosing a number from 5 to 100. 
  • the “Menu icon” option lets you define an icon representing your CPT. Click “Choose dashicon” to select one of the suggested icons. You can also upload the image of your choice by clicking the “Choose an icon image” button.
  • the “Supports” option lets you select the features supported by your WordPress custom post type. For example, you can enable comments, custom fields, etc.
  • the “Taxonomies” option lets you add support for an already registered taxonomy. By default, you will have access to those offered natively by WordPress: categories and tags.
Add a menu icon for the custom post type
You can add a custom icon to your custom post type, for example via a Dashicon class name.

When you are finished, click the “Add Post Type” button. 

You will then see that your new “Films” custom post type is available in your back office.

To add a new film, it works exactly the same as for a post or a page. Click Films > Add New. 

You will land on the WordPress content editor interface (Gutenberg) and you can add any content you like.

Step 3: Add a custom taxonomy to your CPT

To organize all this in even more detail, you can classify your films according to different criteria, thanks to custom taxonomies. 

To create them custom-made, go through the CPT UI > Add/Edit Taxonomies menu. 

For this example, we are going to create the taxonomies “Actors,” “Directors,” and “Genre”. 

As when creating a CPT, you need to enter a slug, a label for the singular and plural forms, and, above all, link your taxonomy to your CPT. 

For this last point, make sure to check the “Movies” box in the “Attach to Post Type” section:

Adding a custom taxonomy to your custom post type.

Click the “Add Taxonomy” button when you are finished. Once your taxonomies have been created, you will find them in the WordPress content editor interface as soon as you add a new post:

Adding taxonomies in the Gutenberg interface.

You now know how to create a custom post type with a plugin like Custom Post Type UI.

Now discover the procedure for doing it manually, with code. 

How do you create a custom content type with code? 

Warning: Creating a CPT in WordPress with code requires experience and technical skills. The slightest mistake or omission in the code can crash your site. This is why we do not recommend this method for beginners. Use the Custom Post Type UI plugin instead if you are in this situation.
If you feel capable of creating a custom content type manually, remember to back up your site beforehand. Then test your code locally or on a staging site before moving it to your production site.

Where and how to create your WordPress CPT: the two possible approaches

To begin with, you should know that there are two ways to develop a custom post type using code.

Option 1: Create a custom post type in the functions.php file 

Your first option is to design your CPT by adding its code to the functions.php file of your child theme. 

Info: A child theme inherits the features and appearance of its parent theme. It allows you to customize a parent theme while ensuring that you do not lose your changes each time the parent theme is updated. Find out here how to create a child theme.  

This option has one major problem: you will no longer have your custom post types if you change themes. 

Option 2: Use a dedicated plugin

To address this “portability” issue, WordPress recommends in its developer resources that you place your CPTs in a plugin, rather than in your theme:

WordPress recommends creating a custom post type in a plugin.

If you change themes, you won’t run into any trouble as long as your plugin remains active on your website. 

Creating a plugin would require a separate tutorial in itself. That is why we are going to stick to the essentials here. You will see how to add a CPT to your functions.php file in order to understand how it works. 

If you ever choose to use the functions.php file method on your site (which is not recommended by WordPress, once again), remember to create a child theme beforehand.

Step 1: Declare a custom post type

The first step is to declare your custom post type. To do this, WordPress recommends using a PHP function (the software WordPress runs on) called register_post_type().

For this example, we will create a WordPress CPT to showcase portfolio items.

For your information, the code shown below comes from an official tutorial provided by WordPress, which you can find here. Feel free to refer to it when you run your tests at home!

Info: If you understand PHP syntax and how a CPT works, you can also use a custom post type generator such as GenerateWP, Meta Box or WPTurbo.

Start by opening your child theme’s functions.php file with the text editor of your choice (Brackets, Sublime Text, etc.).

Add the code snippet below to the end of the file:

//CPT Portfolio function my_custom_portfolio_item() { $args = array(); register_post_type( 'portfolio_item', $args ); }  add_action( 'init', 'my_custom_portfolio_item' );

This is the basic structure of your custom post type. For now, nothing is displayed in your admin interface. 

That’s normal. You’ll need to add what are called arguments. 

Step 2: Customize the CPT

To customize your CPT and, in particular, publicly display its menus in the WordPress admin, replace the previous piece of code with this one:

//CPT Portfolio function my_custom_portfolio_item() {   $labels = array( 	'name'           	=> _x( 'Réalisations', 'post type general name' ), 	'singular_name'  	=> _x( 'Réalisation', 'post type singular name' ), 	'menu_name'      	=> 'Portfolio'   ); 	$args = array( 	'labels'    	=> $labels, 	'description'   => 'Contient des réalisations de portfolio', 	'public'    	=> true, 'show_in_rest' => true, 	'menu_position' => 5, 	'supports'  	=> array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ), 	'has_archive'   => true,   );   register_post_type( 'portfolio_item', $args ); } add_action( 'init', 'my_custom_portfolio_item' );

Now let’s break down this snippet (piece of code) to better understand it. Broadly speaking, there are two main parts.

The labels of your custom content type

The $labels array corresponds to the labels that will be displayed in your admin interface.

To keep it simple, we entered 3 here: 

  • ‘name’, the name of your CPT in the plural; 
  • ‘singular_name’, the name of your CPT in the singular;
  • ‘menu_name’, the label (name) of the CPT that will be displayed in your admin area.

You can go much further and add other options, for example by creating submenus of your choice. 

Find the features offered by the register_post_type() function in the WordPress documentation. 

The arguments 

Next, the $args array contains a list of arguments to customize your custom post type. 

The code we provide includes the following arguments:

  • ‘description’: to explain what the custom post type contains; 
  • ‘public’: to display your WordPress custom post type on the site. Here, the value is set to ‘true’. Choose ‘false’ if you no longer want the CPT to be visible; 
  • ‘show_in_rest’: to make the custom content type available in the WordPress editor (Gutenberg). Otherwise, the classic editor (TinyMCE) will be used; 
  • ‘menu_position’: the position of the CPT in your menu. With the number 5, the custom post type will be positioned below Posts.
  • ‘supports’: the fields displayed in the editing interface for your posts; 
  • ‘has_archive’: to create an archive for the custom post type (leave it set to ‘true’ if you want this).

Once again, you can customize it as you wish using the arguments presented in the WordPress documentation.

For example, it could be useful to change the small icon displayed next to the name of your CPT in your WP admin. 

Also note that the add_action function allows you to declare a directive to WordPress via the init hook, which runs after WordPress has finished loading but before the headers are sent.

Finally, save your functions.php file and return to your administration interface. 

Step 3: Display the custom content type on WordPress

If everything goes well, your custom post type should appear in your sidebar, on the left, below the Posts section.

The Portfolio custom post type in the WordPress admin.
Our custom post type is indeed there, with the default icon provided by WordPress.

From there, you will have the options you have configured. Your content type is available and you can add content from the WordPress editor.

Customizing a custom post type with the WordPress content editor.

If you encounter a 404 error on the front-end interface when you want to display your CPT, this is normal. You need to update WordPress’s URL rewrite rules in your database.

The easiest way to do this is to save your URL permalinks again (do this every time you modify your CPT).

To do this, go to the Settings > Permalinks menu, then click the “Save Changes” button at the bottom of the page.

In principle, everything should return to normal. That’s it for creating your first custom post type. 

To make this CPT match your visual identity and your needs, it is possible (and recommended) to go much further with customization. Note that you can also: 

  • add your own custom taxonomy to your CPTs with PHP; 
  • integrate custom fields, for example using the excellent plugin Advanced Custom Fields (ACF); 
  • modify the page template used by your custom post types, etc.

Summary

A powerful and flexible tool, the custom post type allows you to organize and structure the content of your WordPress site. 

Thanks to our tutorial, you now know that it is possible to create a CPT in two different ways: 

  • either with a plugin like Custom Post Type UI; 
  • or with PHP code to be added preferably in a plugin designed for this purpose. 

Whichever method you choose, the process remains technical, especially if you want to proceed manually (without a plugin).

Following best practices and having strong technical skills are necessary to do things properly, without risking breaking your site. 

Would you like advice and support to integrate your first custom content types into your website? 

Available 7 days a week, the WordPress support service from the Maintenance WP agency will offer you a tailor-made solution that will meet your needs quickly, professionally, and effectively.

Découvrez plus de contenus

fleche separateur

Voir plus d’articles