Complete Steps to Create Custom Post Types in WordPress

custom post type in wordpress without plugin

If you are a WordPress Developer and working on client site where you need to create custom post type in WordPress to addons some new feature. But you don’t want to install any WordPress plugin to create custom post type, then you can create manually by adding the required code in your theme’s functions.php file. Let’s first understand the custom post type in WordPress.

What is Custom Post Type in WordPress?

When you install WordPress, By default it comes with following built-in post types:

  • Post
  • Page
  • Attachment
  • Revision
  • Nav Menu

Post and Page are the most known post type in WordPress. However, today WordPress has become more flexible and advanced. Therefore, You can create your own custom post types and call them whatever you want like Courses, Testimonials, News, Portfolios, Recipe, etc.

Creating a Custom Post Type using Plugin – The Easy Way

The easiest way to creating a custom post type in WordPress is by using a plugin.

Drawback or Problem with plugin

The problem with using a plugin is that when the plugin is deactivated your custom post types will disappear from the Admin Dashboard. Any data you have in those custom post types will still be available, but the custom post type will be unregistered and will not be accessible from the admin panel.

Creating a Custom Post Type Manually

Before start, I want to explain file directory path details, where you need to write custom post type code. So you need to navigate from your WordPress theme directory to functions.php.

Suppose we want to create custom post type for “News”. Now let’s take a look at a short piece of code that adds “News” your custom post type option in the admin panel.

To see how it will appear at the end of your WordPress Admin dashboard, see to the image below.

Create Custom Post Types in WordPress

Whenever you want to create custom post types with your WordPress project, it is required to use init for the hook in add_action(). The register_post_type() function takes the arguments.

Now let’s see a detailed piece of code to adds more options with your custom post type.

$supports: Specifies the post type is compatible and supports all essential features.

$labels: Specifies that the post type is referred properly to the admin area.

$args: Specifies a permalink slug of the news, taxonomy, menu icon, and a menu position.

Now let’s take a look after adding extra features of custom post type in our WordPress Website.

custom post type in wordpress

Create a Template for Archive List

After the code has been developed, the next step is to create a new file called template-news.php in your theme folder. Once this file has been created, add the following code to it.

Select a Template

Now create a new page called News in your WordPress dashboard. Select the News Template from the Template option available in Page Attributes on the right side of your screen. For further reference,  check out the image below and then click the Publish button.

custom post type template in wordpress

Create a News Post

Now create a custom post type News first post in your WordPress website.

wordpress custom post type

Create a Detail Page of Custom Post Type

We must also create a custom post types detail page. To do this, simply create a new file called single-news.php located in your WordPress theme and add the following code.

Let’s take a look at below code parts

In the above code, template-parts/content will depend on your theme content.php file location.

Now it’s time to see how your detail page looks like:

wordpress custom post type without plugin

Also Read: How to Show Related Posts for Custom Post Type in WordPress

Wrapping Words!

Well, I hope you found Complete Steps to Create Custom Post Types in WordPress Without Plugin tutorial helpful for your project. Keep learning!. If you face any problem – I am here to solve your problems.

Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request

Related posts