6 Steps: Create Custom Post Types in WordPress – I

Create Custom Post Types

Custom Post Types in WordPress is the feature which makes WordPress so popular content management platform. By default Post, Page and 5 others are post types available in WordPress. A few example of Custom Post Types are Portfolio, Project, Contact Form 7 or Products in WooCommerce etc.

You might need custom or additional post types for your own need, theme or plugin. You might wish to have a different menu and page under WordPress dashboard to manage your own custom content. For example Movies, Testimonials and Books custom content types with custom fields to input post data.

Further you might need a different archive page to display these post types. Assigning categories or tags, generally saying taxonomies to your custom post types (CPT) is also a common requirement. Exporting your custom taxonomies and custom post types is also a necessary step if you’re developing in a local environment.

The 6 steps article is an attempt to let you learn these process and smoothly apply within your theme starting from custom post types to exporting custom fields you have developed locally. The series of articles is divided into six parts and in this first part, we are going to setup Custom Post Type in our theme.

Create Custom Post Types in WordPress

Before we continue, let’s look what are included in all 6 steps as series of articles:

Create custom post types (reading now)

Adding Custom fields to CPT

Create archive and refresh permalink to display custom fields content

WordPress Category & Tag taxonomies to CPT

Custom taxonomies for custom post type content

Exporting custom fields/taxonomies and further reading

There are few popular plugin to create additional post types along with custom fields and taxonomies for them. I have listed them at end of article. If you are not coding guy, you can install and setup CPT as per your own requirements.

To manually create custom post type, we need to use function namedregister_post_type() in functions.php file of our WordPress theme. I’m going to create Books post type.

Few Notes:

You need to change the term Book, Books, book or books with your custom post type name. Also $td should have name of your theme text domain.

There are plenty of arguments to pass while registering post type with a default value if not supplied. Surely check all about these arguments at WordPress Documentation. If something doesn’t suit your requirement, don’t forget to assign the updated value to args array.

The menu icon can be picked from WordPress Deshicons.

Note that if you rename the post type, your posts/taxonomy/custom filed/slug etc. might get disappeared. In the last post in custom post types series, I have mentions how to safely rename CPT.

Now login to WordPress dashboard and check the post type Books is listed there.

Custom Post Types Plugins

In the next part, we will create some custom fields for these post type we created. But before that below is list of free Plugins from WordPress repository. Drive with them if you prefer to create custom post types, taxonomies and fields using a plugin:

These plugins present you friendly forms in WP dashboard. There you can select or specify required names and all the supported arguments for registering custom post types, taxonomies and fields. If you have liked the post than don’t forget to share the series to let others discover.

You Might Interested In