Skip to content Skip to main navigation Skip to footer

How to Easily Create Custom Post Types in WordPress? (2 Different Methods)

sale_banner

Looking for a way to create custom post types in WordPress?

Custom post types let you add more diversified content and go beyond posts and pages. WordPress has a powerful feature that lets you create custom post types. If you are using WordPress, you must be knowing what a post type is. 

Here, in this blog, we have shown 2 different methods by which you can create custom post types in WordPress. The first is a manual method, for the ones good with coding, and the second is by using a plugin, for the ones who are new to WordPress and beginners at coding. But before that, let’s have a look at what are custom post types and when you need it. 

What Is a Custom Post Type and Why Do You Need It?

Custom post types are additional post types that a user creates based on their needs. There are post types such as Page, Revision, Attachment, and Post which might be enough for anyone with a simple blog topic. But with time, if your content is diverse, then you might need custom post types in WordPress to manage your content.  

Custom post types help you distinguish between different content types for your WordPress website. You just have to evaluate your needs before you create custom post types for your website. Custom post types are mostly needed when you have content that has a different format than a standard post or page. 

For example, if you own an online store, you might need a review post type. With WordPress, you can create a different custom field and a unique category structure. 

Or let’s say you have a blogging site and you want to have coupons and offers on one page. You can’t use the same layout you used in the blogging post type and thus you will have to create custom post-type templates for coupons and offers.

There are two different ways to create custom post types in WordPress.

First Method: Creating Custom Post Types in WordPress Manually

Creating a custom post type manually is better than creating a custom post type with a plugin as your custom post type will not be seen if the plugin is removed or disabled. All the data created in a custom post will still be there but not accessible from the admin area even when you again create the same type of custom post type. 

A point to note while creating a custom post type is that you have to be good at coding, and if not good at coding hire someone for help. It is better to take precautions rather than enter the wrong code and put your site at risk. 

To create a custom post type manually, you will have to enter the required code in the theme’s function.php file or a site-specific plugin. 

Let’s look at an example of how to create a custom post type. If you wish to create a custom post type for coupons on your blogging site, then you will have to enter the below-mentioned code snippet with arrays. 

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

Source: wpbeginner.com

Here, in the above-mentioned code, there are two parts of an array. The first part is labeled and it is an array itself. And the second part contains arguments like archive and public visibility. This way, you can edit codes in function.php or a site-specific plugin to create custom post types without plugins. 

If you need more assistance, you can hire WordPress engineers from JustHyre.

Second Method: Creating Custom Post Types in WordPress With a Plugin

The easiest way to create custom post types is by using a plugin. Plugins don’t require even a single line of code and thus it becomes easier for beginners and non-technical people to create custom posts in WordPress. Plugins are super easy to install and use. 

create custom post types- install plugin

To create custom post types in WordPress with a plugin, we suggest you use Custom Post Type UI. On the WordPress sidebar, click on “Plugins” and in the search field, search for the Custom Post Type UI. Click on “Install Now”, to install the plugin, and don’t forget to download it. 

Once done with the installation, you will see CPT UI on your WordPress sidebar. Click on that and navigate to “Add/Edit Post Type”. From here, you will be able to create new custom post types for your WordPress website. 

create custom post types- add new post type

There are a few necessary fields that you should fill in to create custom post types. Firstly, you will have to enter the slug for your custom post type. For example, you want to create custom post types for “Coupons”. This slug will be used in URL and WordPress queries. 

Next, you will have to enter the plural and singular names for your custom post types. After that, you can click on “Auto-Populate Labels” to automatically label fields down below, which will eventually save you precious time. 

create custom post types- additional labels

If you don’t want to click on the above link, then you can scroll down to the “Additional Labels” section and manually insert data in each field. The labels in the “Additional Labels” will be used throughout the WordPress user interface when you are managing your content on your WordPress website. 

Next, you can set attributes for your custom post type from the post type settings. There is a brief description of each field. 

Once done with all settings, click on “Add Post Type” to create a custom post type. 

create custom post types- add post type

Wrapping Things Up

And that’s it for this blog. We hope this blog has helped you to create custom post types in WordPress. If you are good at coding and are confident in it, then only create custom post types manually. Otherwise, we suggest you create a custom post type with a plugin as it is more safe and easy to use. Custom post types can help you manage your diverse content. 

If you like reading this blog, also read our step-by-step guide on How to Fix the “File Type Is Not Permitted” WordPress Error with Easy Methods and How to Embed a Video on WordPress? (2 Different and Easy Methods)

icons icons icons icons icons icons icons

Stuck Somewhere?
Connect With JustHyre

Hire WordPress Engineers for custom jobs like Website Customization, SEO Optimization, Clearing a Hacked Website, Installation & Configuration & more.

Connnect with JustHyre
0 Comments

There are no comments yet

Leave a comment

Your email address will not be published.