How to Create in WordPress Custom Post Types

How to Create in WordPress Custom Post Types
Share

WordPress offers excellent customization. That is why you can create custom post types in addition to posts and pages.

Before we share the exact procedure to create custom post types in WordPress, let us understand what these are.

What are custom post types in WordPress?

Post types in WordPress refer to the type of content you want to upload. By default, some post types in WordPress include:

  • Post
  • Page
  • Attachment
  • Division
  • NAV menu

If you want to upload some type of content on WordPress which does not classify into these post types, you can create custom post types. As the name suggests, you can customize this post type according to the content you upload.

Now that you know the definition of custom post type, it is time to look at how to create the same.

How to Create Custom Post Types WordPress?

You can create custom posts using WPCode or using a plugin. We will go into the details of both these methods below.

Method 1: Using WPCode

How to Create in WordPress Custom Post Types

WPCode is a plugin that allows you to add the code to your WordPress theme. You can use it not only for creating a custom post type but for many other purposes.

Step 1: Install the plugin:

After logging into the WordPress dashboard, install the WPCode Plugin (Click here to know how to install a plugin).

Step 2: Click on Add Snippet:

How to Create in WordPress Custom Post Types

After navigating and activating the plugin, go through the left-hand sidebar to click on the code snippets option and add the snippet.

Once you do so, it will allow you to add code and upload various files. Click on the “Add custom code” option.

Step 3: Give a title:

On the next screen, you have to give a title like “Create Custom Post Type” and toggle the Active button to activate the code.

Step 4: Add the code below:

In the code preview dialogue box, add the following code:

How to Create in WordPress Custom Post Types

You can replace the word product/products with the post type you want to create. The rest of the code will remain the same irrespective of the custom post type you want to create.

Step 5: Click “Save Snippet”:

After entering the code in the code preview dialogue box, you have to just click save snippet.

This will create a new custom post type in WordPress.

Method 2: Using a Plugin

Many Webmasters do not want to fidget with code to create a custom WordPress post type. If you are one of them, this method will serve you well.

Step 1: Install the plugin:

The plugin to install and activate is Custom Post Type UI. The procedure to install this plugin and activate it is similar to any other plugin. Once you activate it, move to the next step.

Step 2: Select Add/Edit Post Types:

In the navigation bar, you can view the CPT UI option. Click on the dropdown menu to view Add/Edit Post Types.

Step 3: fill in the details:

How to Create in WordPress Custom Post Types

The first field is post type slug. This is the URL slug for that custom post type. It can contain numbers, alphabets, Latin characters. If we extend the above example, it can be “eCommerce-products” or “products”.

The next is the Plural Label. It is used in the admin menu. It can be eCommerce products.

Below is the singular label which can be an eCommerce product.

Once you enter these details, you have to click on the ad post button.

Undoubtedly, this is the easiest way to add a custom post type. In the code, anything can go wrong. Even if you miss out on a single character in the code method, it won’t work. Thus, it is best to use this method.

Now that you know both methods, it is time to understand the difference between custom post types and normal posts in WordPress.

What is the difference between a post and a custom post type?

For an average user, a post type categorized as a custom post will not appear any different. Of course, you might have to decide how it appears on your front end, but it does not make any difference for an average user.

When you look at the technical difference between the custom and regular posts on your website, you will realize that the custom post type will have a different post_type value in the database.

Thus, when you go through the database, it is easy to understand which post is a custom post type and which is a regular one.

When does it make sense to create custom post types in WordPress?

Before creating custom post types in WordPress, it is essential to understand its use cases.

1. For posting eCommerce products:

WordPress is a pretty versatile platform. It is not only used for sharing blog posts in content, but you can also use it to list e-commerce products and sell them.

The problem is that the regular database and design of WordPress are such that it predominantly relies on you sharing content. That is why, when you want to post e-commerce products, it is a good idea to create a custom post type.

This way, whenever you want to share a regular post, you can do so, and whenever you want to add a new e-commerce product to the inventory, you can do that using the custom post type.

It will make it easy to organize both types of posts as well. That way, using widgets and menus, you can display the products and posts separately without manually sorting them out.

2. For portfolio creation:

It is easy to create a portfolio using WordPress. You can display the resources using such a portfolio and garner more clients.

To better organize the portfolio and separate it from regular posts and content, it is advisable to go with a custom post type. Then, it becomes really easy to share the type of content you want publicly and keep the rest of the content private or organize both posts per your need.

3. For publishing events:

You can publish the event on your WordPress website whenever you are attending an event, exhibition, or webinar you want your readers to know about. However, such a post is pretty different from the regular one you share on your WordPress website.

If you frequently attend such events, creating a custom post type is better. That way, you can link all such events easily. Even if such events are in the hundreds, using a custom post type and calling it from different pages will allow you to list all the events you have attended. It will eliminate the manual sorting of the events, and you can directly synchronize them in the post, page, or widgets you want using such custom post types.

4. For publishing unique content:

WordPress posts are the most common type of content published by Webmasters using WordPress. However, that doesn’t mean there is no other type of content that Webmasters want to publish.

Whenever you want to publish any unique content, whether it be tables, presentations, slideshows, or anything else, it is better to create a custom post type. That way, keeping everything organized is certainly easy.

4. Temporary content:

Many times, the relevancy of a post is only for a limited time. After a certain date, you might remove it from your website.

If you just want to delete a single such post, doing so is easy. However, if you have multiple such posts you need to publish and then delete, you can create a custom post type and later delete the entire post type along with the posts. That will help you cover the traces and share content for a limited time.

It makes perfect sense to create a custom post type in all these cases. Managing content in such cases is easy and even deletion of such custom posts becomes easy.

We will now answer a few queries regarding such post types to help you know them better.

FAQ:

How do I show custom post types in the front in WordPress?

The easiest way to display a custom post type in the front end is to go to the appearance option and then click on menus. After that, you can add a custom link pointing to the custom post type in the navigation menu. That will certainly display the custom post type in the navigation menu allowing the reader to navigate to such posts easily.

What is the default post type in WordPress?

By default, WordPress offers various post types. The most common ones are page or post. It does not enforce any particular post type as default. You can select whether you want to publish a post or a page.

Conclusion:

Thus, WordPress does offer custom post types. You can create ample post types. Using the guide above, you can do so by adding code or simply by filling up a few entries using a plugin. Follow any of these methods, and you can create custom post types in no time.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top