Published

Update

6 minutes

Have you ever heard of a custom post type? Even if you're new to WordPress, it's a term that must have come up in your ears. 

It must be said that this is about one of the most powerful WordPress toolsAnd yet… By default, the CMS (Content Management System) doesn't even offer this feature to its users!

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

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

Flexible and scalable, a type of personalized content (its translation into French) will help you to classify and prioritize your content in a much more nuanced way than with an article, for example.

Do you want to know how to take advantage of this on your WordPress site? You've come to the right place. 

By the end of your reading, you will 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 the user to categorize and manage your content by configuring them himself. It can be designed using a dedicated plugin or PHP code. 

Introduced with the release of WordPress version 3.0 (2010), custom post types (CPTs) are not included by default in every new WordPress installation. You must design them yourself if needed. 

This is one of the things that differentiates them from 7 types of content present by default on every WordPress site, such as :

  • the articles (posts); 
  • the pages;
  • the attachments, i.e. your media (images, videos, PDFs etc); 
  • revisions, i.e. backups of your content (articles & pages);
  • navigation menus;
  • custom CSS;
  • the changes (changesets) made in the Customizer tool.

Like other default content types (e.g., posts and pages), custom post types on WordPress are displayed in the sidebar of your administration interface, once created. 

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

In fact, many popular plugins use their own custom content types on WordPress. This is the case, for example, with the well-known WooCommercewhich allows you to transform your WordPress site into an online store.

The ecommerce plugin, for example, offers a CPT called "Products":

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

Why create a custom content type on WordPress?

In general, custom post types on WordPress allow you to better organize and prioritize your site's content.

In detail, their use offers several notable advantages: 

  • you gain flexibility, since you can customize each type of personalized content 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 navigate. This creates less friction and increases your chances of keeping visitors on your site to encourage them to take the desired action (purchase, file download, form completion, etc.); 
  • You are not limited in the number of CPTs that you wish to design. You can create 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.This gives you complete control over the presentation and style of each type of content.

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

The different possible use cases

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

Do you think a custom post type is necessary for your WordPress site but are hesitant 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 as you wish; 
  • you want the appearance of new content to be different from the types of content already present on your site; 
  • You need additional fields to organize your content. For example, if you maintain a food blog, you might want to list your recipes by ingredients, difficulty, cooking time, etc.;
  • The content you want to create doesn't correspond to its "traditional" use on WordPress. For example, a post is used to create content for your blog, content that is meant 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 that you are in charge of managing a blog dedicated to cinema. 

To make everything clearer and easier to understand, you would like rank the films you have reviewed depending on various criteria: 

  • actor ; 
  • duration ; 
  • gender ; 
  • release date; 
  • notation 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 might quickly find yourself with numerous categories on your sitemaking the organization less clear for you, your site users, and your visitors; 
  • The categories and tags of your blog posts do not represent the most logical way to classify your content.Imagine the number of categories you'll have to create just to differentiate series by type (action, horror, drama, comedy, etc.)!

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

  • events;
  • creations from your portfolio; 
  • products for your online store; 
  • testimonies; 
  • 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 theory, it's time for practice. You will now discover how to create your own custom post types on WordPress. 

What are the prerequisites before creating a CPT?

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

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

  • save your site (files + database) before any technical manipulation. For this, use a plugin like UpdraftPlus, or a maintenance tool like WP UmbrellaIn case of a problem, you can easily restore your site in just a few clicks; 
  • if possible, First, create your custom post type in a test environment. before putting it into production (on your online site).
    Again, this provides cover in case of a technical error. To conduct your tests with complete peace of mind, work locally, for example, with the Local toolYou can also rely on the tool WordPress Playgroundwhich allows you to simulate a WordPress environment on your web browser:
The WordPress Playground tool allows you to simulate a WordPress environment and create custom post types.
The WordPress Playground tool

How to design a custom post type on WordPress using a plugin?

Let's now look at the first method for creating a custom post type on WordPress. It involves using a plugin. 

This is the easiest and fastest way to get started. It is particularly suitable for beginners and non-technical users. – among other things – because it does not involve manipulating code. 

On 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); 
  • there is easy to handle and use
  • Its settings are available in French.
  • It is very highly rated by its users; 
  • there is frequently updated
  • It is developed and maintained by a WordPress specialist agency (WebDevStudios) which has a very good reputation within the ecosystem.
Screenshot of the Custom Post Type UI plugin on WordPress.

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

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

To begin, go to the Extensions menu > Add an extension.

In the search bar, type "custom post type ui", then install AND activate the extension:

Installation of the Custom post Type UI extension on the WordPress back office.

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

This is where you access the extension's settings menus:

The WordPress CPT UI settings menu.

Step 2: Create a custom post type

Next, click on 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 section called "Default Configuration". You are asked to fill in the following information: 

  • Publication type slugThis is the part of the URL that will contain your CPT name. Here, put "films" in lowercase. Do not use hyphens, underscores, or other special characters; 
  • Label for the plural (Films); 
  • Label for the singular (films); 
  • Auto-fill the labelsIf you click the "Fill additional labels based on selected labels" link, Custom Post Type UI will automatically generate the label names. This saves you some time, but the translation isn't perfect. Therefore, we recommend manually editing each label after clicking the link.
Default configuration of a custom post type with the Custom Post Type UI plugin.

Label customization

The "Additional Labels" section contains around thirty labels, the titles of which you can customize.

The translation of the CPT name that will be displayed in our administration sidebar is not suitable for us ("My Movies"). We choose to rename it more simply "Movies". 

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

Customizing labels with the Custom Post Type UI plugin.

Custom content type settings on WordPress

In the following section, you'll find a whole series of settings on a single page. The default settings will do the job, but you can still make some adjustments if you wish. Here are a few suggestions to help you: 

  • the "Menu Position" option This allows you to choose the location of your custom post type on your admin sidebar. You can move it up or down by choosing a number from 5 to 100. 
  • the "Menu icon" option This allows you to define an icon representing your CPT. Click on "Choose Dashicon" to select one of the available icons. You can also upload an image of your choice by clicking on the "Choose Icon Image" button.
  • the "Media" option This allows you to select the features supported by your custom WordPress post type. For example, you can allow comments, custom fields, etc.
  • the "Taxonomies" option This allows you to add support for a previously registered taxonomy. By default, you will have access to those natively offered 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 class name Dashicon.

When you are finished, click the "Add a post type" button. 

You will then see that your new custom post type "Movies" is available on your back office.

To add a new movie, it works exactly like adding an article or a page. Click on Movies > 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 of this in even more detail, you can classify your films according to different criteria, using custom taxonomies. 

To create them custom-made, go to the CPT UI menu > Add/edit taxonomies. 

For example, we will create the taxonomies, "Actors", "Directors" and "Genre"

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

For this last point, be sure to check the "Films" box in the "Attach to publication type" section:

Adding a custom taxonomy to your custom post type.

Click the "Add taxonomy" button when you're finished. Once your taxonomies are created, you'll find them in the WordPress content editor interface whenever you add a new post.

Adding taxonomies to the Gutenberg interface.

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

Now discover how to proceed manually, using code. 

How to create a custom content type using code? 

Please note : Creating a CPT (Custom Post Type UI) on WordPress using code requires experience and technical skills. Even the smallest error or omission in the code can crash your site. Therefore, we do not recommend this method for beginners. If you find yourself in this situation, we suggest using the Custom Post Type UI plugin.
If you feel confident creating a custom content type manually, remember to back up your site beforehand. Then test your code locally or on a staging site before deploying it to your live site.

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

To begin, 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 

First option for you: design your CPT by adding its code to thee file functions.php of your child's theme

Info A child theme inherits the functionality and appearance of its parent theme. It allows you to customize a parent theme while ensuring that you don't lose your changes with each parent theme update. Discover here how to create a child theme.  

This option has a major problem: you will no longer have your custom post types if you change the theme. 

Option 2: Use a dedicated plugin

To address this "portability" issue, WordPress recommends in its resources to developers de place your CPTs in a plugin, rather than in your theme:

WordPress recommends creating a custom post type in a plugin.

If you change your theme, you won't be bothered as long as your plugin remains active on your website. 

Creating a plugin would require a separate tutorial. That's why we'll get straight to the point here. You'll see how to add a CPT to your file functions.php in order to understand the mechanics of operation. 

If you ever choose the file method functions.php at home (which is not recommended by WordPress, 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. For this, WordPress recommends using a PHP function (PHP is the software on which WordPress runs) called register_post_type().

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

For your information, the code presented below comes from an official tutorial provided by WordPress. You can find it hereFeel free to refer to it when you conduct your tests at home!

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

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

Add the following code snippet 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. Currently, nothing is displayed on your administration 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, to publicly display its menus in the WordPress admin area, replace the previous code snippet 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' );

Let's now break down this snippet (piece of code) to better understand it. Roughly speaking, there are two main parts.

The labels for your custom content type

The array $labels corresponds to labels that will be displayed on your administration interface.

To put it simply, we've entered 3 of them 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 on your administration.

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

Discover the features offered by the function register_post_type() on the WordPress documentation. 

The arguments 

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

The code we are proposing offers the following arguments:

  • 'description' : to explain what the custom post type contains; 
  • 'audience' : to display your custom post type WordPress on the site. Here, the value is set to 'true'. Use 'false' to hide the CPT; 
  • 'show_in_rest' : to make the custom content type available on 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 the Articles.
  • 'supports' : the fields displayed in the editing interface for your publications; 
  • 'has_archive' : to create an archive of the custom post type (leave on “true” if you wish).

Once again, you can customize it to your liking using the arguments presented in the WordPress documentation.

For example, it might be interesting to change the small icon that appears next to your CPT name on your WP admin. 

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

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

Step 3: Display the custom content type on WordPress

If everything is working correctly, your custom post type should appear in your sidebar, on the left, under the Articles section.

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

From there, you will have access to 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 trying to view your CPT, this is normal. You need to update WordPress URL rewriting rules in your database.

The easiest way to achieve this is to re-register your URL permalinks (do this every time you modify your CPT).

For this purpose, Go to the Settings menu > Permalinks, then click the "Save changes" button at the bottom of the page.

In principle, everything should be back to normal. That's it for creating your first custom post type. 

To ensure this CPT aligns with your brand guidelines and needs, it's 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 prioritize 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
  • either with code PHP should be added as a priority in an extension designed for this purpose. 

Regardless of the method chosen, the process remains technical, especially if you wish to proceed manually (without a plugin).

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

Do you want advice and support to integrate your first types of personalized content onto your website? 

Available 7 days a week, WordPress support service The WP Maintenance agency will offer you a tailor-made solution that will meet your needs with speed, professionalism and efficiency.

Discover more blog articles

separator arrow

See more articles