How to Create Custom Post Types in WordPress With or Without Plugin?

Team DiviFlash

Updated: August 28, 2023
Table of Contents

Exploring a way to create custom post types in WordPress? If you are, that means there is a need to insert your own specific custom content type.

And, a successful inclusion combines a distinguished post type other than the default post type like the post, page, attachment, nav menu, custom CSS, revision, and so forth.

Here’s what custom post types like Reviews, Recipes, Tutorials, Books, and any other blog post types. It largely depends on the preferred types of content of your site.

You can also think of the categorization of posts. However, for a better content management system, the custom type of post can be an effective WordPress mechanism. It is also pretty much evident among the users as well.

At least, some of the following things that I can think of:

  • Expand website as own requirement.
  • Have options like Add New, and Post List with the new navigation menu item.
  • Easily observe from the admin menu because of a separate post list.
  • Add the custom post type menu anywhere in the WordPress sidebar.
  • Decide whether or not the post type is searchable.
  • Control the access level of users and visitors.
  • Insert metadata with custom fields and custom taxonomies.

And, there are many other reasons to jump-start adding custom post types.

Now, let’s take a detailed way to get this done, and get it done easily.

How to Add Custom Post Type in WordPress?

In this post, you will see two ways of adding a custom post type. The first one is without using plugin, by adding custom code to function.php. Another one is, using a plugin.

Plus, you will also learn the easiest way to add custom fields in this how to create WordPress custom post type tutorial.

How to Create Custom Post Type in WordPress without Plugin?

To create your custom post type, navigate to WordPress Dashboard> Appearance> Theme File Editor> function.php. Here we will write a new function for our custom post type. But, before registering your custom post type, keep in mind the following parameters:

  • Don’t hook the post type registration before the init action.
  • Post type key can only contain up to 20 characters.
  • Apply only lowercase alphanumeric characters, dashes, and underscores for the post type key.

Now, let’s see our custom post type code below. There is a new post type called “Movies” in the admin panel after applying our code in the function.php. It also encompasses options also known as custom taxonomies like All Movies, Add A New Movie, Categories, Tags, etc.

We are also giving a few notable breakdowns of our code. It will help you to change or write the code according to your custom post type. First, we will explain the $args array.

// Register Custom Post Type
function custom_post_type() {

	$labels = array(
		'name'                  => _x( 'Movies', 'Post Type General Name', 'text_domain' ),
		'singular_name'         => _x( 'Movie', 'Post Type Singular Name', 'text_domain' ),
		'menu_name'             => __( 'Movies', 'text_domain' ),
		'name_admin_bar'        => __( 'Movies', 'text_domain' ),
		'archives'              => __( 'Item Archives', 'text_domain' ),
		'attributes'            => __( 'Item Attributes', 'text_domain' ),
		'parent_item_colon'     => __( 'Parent Item:', 'text_domain' ),
		'all_items'             => __( 'All Movies', 'text_domain' ),
		'add_new_item'          => __( 'Add New Item', 'text_domain' ),
		'add_new'               => __( 'Add A New Movie', 'text_domain' ),
		'new_item'              => __( 'New Item', 'text_domain' ),
		'edit_item'             => __( 'Edit Item', 'text_domain' ),
		'update_item'           => __( 'Update Item', 'text_domain' ),
		'view_item'             => __( 'View Item', 'text_domain' ),
		'view_items'            => __( 'View Items', 'text_domain' ),
		'search_items'          => __( 'Search Item', 'text_domain' ),
		'not_found'             => __( 'Not found', 'text_domain' ),
		'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
		'featured_image'        => __( 'Featured Image', 'text_domain' ),
		'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
		'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
		'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
		'insert_into_item'      => __( 'Insert into item', 'text_domain' ),
		'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
		'items_list'            => __( 'Items list', 'text_domain' ),
		'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
		'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
	);
	$args = array(
		'label'                 => __( 'Movie', 'text_domain' ),
		'description'           => __( 'Movie Review', 'text_domain' ),
		'labels'                => $labels,
		'supports'              => array( 'title', 'editor', 'thumbnail', 'custom-fields' ),
		'taxonomies'            => array( 'category', 'post_tag' ),
		'hierarchical'          => false,
		'public'                => true,
		'show_ui'               => true,
		'show_in_menu'          => true,
		'menu_position'         => 5,
		'show_in_admin_bar'     => true,
		'show_in_nav_menus'     => true,
		'can_export'            => true,
		'has_archive'           => true,
		'exclude_from_search'   => false,
		'publicly_queryable'    => true,
		'capability_type'       => 'page',
	);
	register_post_type( 'post_type', $args );

}
add_action( 'init', 'custom_post_type', 0 );

Here are the $labels arrays:

  • name: Write the name of the post type in plural form. In our code, it is “Movies”.
  • singular_name: The representative of a single post of this type. Our name is “Movie”
  • menu_name: Can choose a different name for the menu label.
  • add_new_item: Alter option to change the default “Add new post/ Add new page”.
  • add_new: Can rewrite the menu item to add new blog post. For ours: “Add A New Movie”
  • new_item: Editing option for the label of new item page or post title.
  • edit_item: Can give a new label for editing a singular item.
  • featured_image: st the ‘Featured Image’ meta box title.
  • set_featured_image: Change the default setting label “Set featured image”
  • items_list: Give alternative text for the table hidden heading.

So, we have shown some common $labels arrays and for more details, check here.

Next, go for $args arrays. Use this list to learn more. For now, let’s define our arguments:

  • Labels: The label array conveys text such this list as add new, edit item, navigation menu item and so on that is displayed on the admin page.
  • Description: A short detail of your custom post type. We described as “Movie Review”.
  • Taxonomies: se the taxonomies argument while registering a custom post type. If you skip taxonomies and post type will not be connected.
  • Hierarchical: Set it true to use your custom post type as pages or make it false for post preference.
  • Public: Control the visibility of custom post type between the author and visitors. For instance, set it true to show in the WordPress dashboard.
  • Menu Position: The positioning of custom post type in the backend. Set it to 5 for showing below posts. But before that show ui and show in the menu must set true.
  • Has archive: By setting it true- (1) an archive page enabled for the custom post type, (2) by default use the post type as archive slug.
  • Publicly queryable: Enabling it queries can be performed as parse_query.
  • Capability Type: It works as a base to construct capabilities if there isn’t any explicit function with the “capabilities” parameter.
  • Support: Another worth mentioning array is “Support”. With this option, you can define WordPress meta boxes and fields and other post editor features according to your preference.

The title and editor are enabled by default. But, like our code, you can also write “False” to disable them. Check this list of post editor features, which you can add with the support array.

How to Create Custom Post Type in WordPress with Plugin?

Custom coding is not an easy task to do for everyone. So, often WordPress users choose a flexible option where they use a plugin to create a custom post type.

There are many WordPress plugins available, like Custom Post Type UI, Pods, Toolset, etc. But today I am going to show you one of the most popular on the list: Custom Post Type UI (CPT UI).

It’s an effortless process of adding custom post type with this plugin.

Here are three simple steps to follow:

Step 1: Start with installing and activating the CPT UI plugin. It is available in WordPress free repository. From your WordPress admin panel, navigate to Plugin> Add New and browse for CPT UI via the search box.

Now, the CPT UI plugin is on your screen. Install and activate it. Once successfully done, head over to the second step.

Step 2: Again, from the WP admin area, click CPT UI> Add New Post Type. This will bring the CPT UI interface. Put your Custom Post Type Slug.

“In WordPress, Slug is known as a word or words that refer to a post, tag, category, and page. And, since slug is a part of the URL, it only contains letters and numbers. Here, the space between words will automatically count as underscores.”

Afterward, add the plural and singular label of the custom post type. Then, alongside the Auto-populate labels option, click the “Populate additional labels based on chosen labels” to automatically fill these additional labels or select “clear labels” if you don’t want them.

Later, you can individually fill those labels. These labels basically let you define the WordPress interface. For example, you can edit the text used in the post type admin submenu.

And, it is easy as there will be a short explanation below every label box. This advantage is also true for boxes under the setting.

Using these options, you can set up the WordPress custom post type in a detailed way. For example, whether such custom posts will be publicly queryable or not.

Now if you scroll down, you will see another notable feature of this plugin, which is the supports option. There are post editor features and if you check the boxes, these features support will be available for your custom types of content.

Note here, for custom fields support, don’t forget to check the custom fields box in the support area. And, shortly we are covering about custom fields.

NB: Checking the last “None” option means you don’t want any of these feature support. Moreover, Featured Image and Post Formats options required theme support to use.    

Step 3: Now you will do the final step. Just hit the “Add Post Type” button. Done! A new label, namely “Movies” successfully appears on the left sidebar. Start adding your first custom post types.

Now, you found a custom post type. But on most occasions, a custom post type alone can’t fulfill your satisfaction. There are other supporting bits for the post which you want to include.

For instance, for a custom post type called: Movies, there would have other information like All Movies, Add A New Movie, Movie Category, Movie Length, Ratings, number of views, etc. Here, the custom field comes into play.

What is a Custom Field?

Custom fields let you attach various information dedicated to the post. These are the specific metadata of the post that WordPress saves. Thus, your post can be ordered and filtered through this post metadata.

Hopefully, you have a clear resemblance of custom post type and custom fonts. But, sometimes both functionalities are enough to leave one confused.

Because, if you compare custom post type and custom fields, there are some significant similarities. They actually go hand in hand for the reasons below:

  • Custom post type define the main item, whereas custom fields contain the sub-topics for a specific content type.
  • There could be a few custom fields for a particular custom post type, like the video custom post type example above in this article.
  • Custom post type can be filtered by a custom field.

So, this was our comparison. All you need to do is coordinate them in a user-friendly way. And, you definitely want them. So learn to create custom fields.

How to Create Custom Fields?

Now, let’s see how to add custom fields. This is the easiest way as we are using a plugin. You can do it by only following the simple steps below.

Step 1: First, install the ACF plugin and activate it. To do this, follow the same installation and activation process of CPT UI.

Step 2: Up next, we will add our first Field Group. Under a field group, we will insert the custom fields. From your WordPress admin screen, click Custom Fields> Add New.

Step 3: Give a name to your field group in the first box.

Step 4: Then come to the second box, and select “+Add Field”. It will open up a field form with a range of options. Fill them out as you needed. These options will let you describe and give instructions to the custom fields. Simply click again the “+Add Field” to include another custom field.

Step 5: From the third box named “Location”, you can assign a rule that will show the field group in the selected post type. Hitting the “and” button in the sharp right will add a new rule. Also, create multiple rule groups by clicking the “Add rule group”.

Step 6: In the last box, you have multiple setting options to set the look of custom fields in the post editor like label placement, style, position, and so on. Place them as you want.

Step 7: Once you have included all your custom field data, click the publish button on the right side of your device screen.

So, now you have successfully added your custom groups. 

Conclusion

That’s it. By now, you have the solution of how to create custom post types in WordPress. You can consider writing a custom code or using a plugin for more convenience. Knowing to add custom fields is also another benefit.

But, if you still have any questions regarding custom post type, custom fields, or even any WordPress queries. Just let us know in the comment. There is always a dedicated team to answer you.

Team DiviFlash

At DiviFlash, we are more than just a team – we are a collective of Dev Experts, Word Artists, Design Virtuosos, and Marketing Maestros, all united by our profound expertise in Divi and WordPress. Our mission is to provide you with accurate, insightful, and in-depth content aimed at enriching your understanding of Divi, WordPress, and the art of web design.

0 Comments

Submit a Comment

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