The best way to create WordPress custom post type

Last Updated: April 27, 2023 - Posted In: Plugins ,Tutorials
Do you want to learn the best way to create WordPress custom post type?

You can add more different content to your website by using custom post types without using posts and pages. They convert your WordPress site into a powerful content management system (CMS)  from a blogging platform.

In this article, we’ll show you how to create custom post types in WordPress easily.

What Is Custom Post Type in WordPress?

Post types are used on your WordPress website to assist identify various content formats in WordPress. Pages and posts are both post types, but they are designed to serve different purposes.

WordPress comes with a few different post types by default like- Posts, Pages, Media, Menu, etc

Also, you can create wordpress custom post type. They are helpful when creating content that isn’t in the same post or page format. For instance, if you manage a website with movie reviews, you’ll need to create a post type for movie reviews. For portfolios and testimonials, you may also make custom post types. Different custom fields and custom category structures are available for custom post types.


Method 1: Create wordpress Custom Post Type Using a plugin

A plugin is a simple way to build a custom post type in WordPress. Because it is secure and super easy, this method is recommended for beginners. The Custom Post Type UI plugin needs to be installed and activated initially.

After activation, you have to go to CPT UI » Add / Edit Post Types to create a new custom post type. It would be best if you selected the “Add New Post Type” tab.

You must first give your custom post type a slug, such as “movies.” Only letters and digits are allowed in this slug because it will be used in both the URL and WordPress queries. Below that, you must  add the plural and singular names for your custom post type

After that, if you want, you can click on the “Populate additional labels based on chosen labels” option. This will automatically fill out the other label fields below, which will typically save you time.

Finally, click the ‘Add Post Type‘ button to save and create your custom post type. Just that. You can now add content because you have successfully built your custom post type.

If you want to display your custom post on the home page, please check this article  How to display custom post type on a WordPress page 



Method 2: Create a Custom Post Type Manually Using Child-theme

You must add code to your theme’s functions.php file in order to create a custom post type. Generally, we wouldn’t advise this to anyone but really experience users because even a small error could break your website.  Also if you update your theme, the code can be removed.

However, we will be using Child-theme, the easiest and safest way for anyone to add custom code to your WordPress website. You can even add more code in the theme for the future.

First, you will need to install and activate the free Theme editor plugin.

After activating the plugin you will notice a new admin menu called “Theme Editor” on the left bottom side of WordPress. Click “Child theme“. then you will find an option to analyze your theme. Simply press analyze button.

After complete analysis, you can now create a child theme.  You will see a button for “Create Child Theme“. Click it and the child theme will be created automatically.

Well done, We’ve created a child theme. Now active the child theme from Appearance -> Themes. Then we can code into it safely.

Click theme editor and you will see a text area to write. On the right side, you will see a menu. Click functions.php.

child theme function file

After that, Simply paste the following code into the Code text-area.  Any theme with this code will create a basic custom post type called “Movies“. which will show in your admin sidebar.

// Our custom post-type function
function create_posttype() {
    register_post_type( 'movies',
    // CPT Options
            'labels' => array(
                'name' => __( 'Movies' ),
                'singular_name' => __( 'Movie' )
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'movies'),
            'show_in_rest' => true,
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );

If you want to display your custom post on home page, please check this article  How to display custom post type on a WordPress page 

Inline Feedbacks
View all comments