How to create custom post types in WordPress

WordPress comes with default post types for blog posts, pages, attachments, revisions, and more. However, when you want to create more unique content that meets the specific needs of your business or personal site, these default custom post types can be limited.

You can overcome this limitation by creating your own custom post types to extend the functionality of WordPress. You can create just about any type of custom post, ranging from custom events to product testimonials, staff profiles, and more.

In this article, we are going to show you some methods to create custom post types in WordPress.


How to create custom post types using plugins

The two main ways to add custom post types in WordPress are to either use plugins or code them yourself. Using a plugin is usually the preferred method if you are looking for a quick and easy to implement solution.

But additional plugins on your WordPress site can turn into bloatware, slowing down your site speed. If you are comfortable with writing code, we recommend the manual method.

If you prefer to use a plugin, however, the process is straightforward. There are several plugins to choose from, most of which are easy to use, such as Custom Post Type Maker, Pods, and Custom Post Type UI.

We will recommend Pods because it has over 100,000 installations and comes highly recommended by WordPress experts and users. While using a plugin is a viable method of creating custom WordPress post types, this article will focus more on how to do it manually.

VIDEO OF THE DAY MAKEUSE

Manual creation of custom post types

You can create a custom post type just by adding a little code to your theme functions.php to file.

Below is a detailed piece of code that adds more options to your custom post type. In the WordPress backend, go to Appearance> Theme Editor> Theme Functions (functions.php).

The first thing you will need to do is choose a name for your new function. In this example, we’ll create a custom post type to create dedicated profiles for partners in a law firm or consulting firm.

We will call our new function cp_post_type_partners.

Copy the following code and paste it at the bottom of the file:

/*Custom Post type start*/
function cp_post_type_partners() {
$supports = array(
'title', // post title
'editor', // post content
'author', // post author
'thumbnail', // featured images
'excerpt', // post excerpt
'custom-fields', // custom fields
'comments', // post comments
'revisions', // post revisions
'post-formats', // post formats
);

$labels = array(
'name' => _x('partners', 'plural'),
'singular_name' => _x('partner', 'singular'),
'menu_name' => _x('partners', 'admin menu'),
'name_admin_bar' => _x('partners', 'admin bar'),
'add_new' => _x('Add New', 'add new'),
'add_new_item' => __('Add New partner'),
'new_item' => __('New partner'),
'edit_item' => __('Edit partner'),
'view_item' => __('View partner'),
'all_items' => __('All partners'),
'search_items' => __('Search partners'),
'not_found' => __('No partner found.'),
);

$args = array(
'supports' => $supports,
'labels' => $labels,
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'partners'),
'has_archive' => true,
'hierarchical' => false,
);
register_post_type('partner', $args);
}
add_action('init', 'cp_post_type_partners');
/*Custom Post type end*/


This code leverages WordPress-specific PHP which allows you to register a custom post type without having to create it completely from scratch.

Update the file and refresh the page, and your dashboard should have a brand new menu item called The partners.

That’s it! To view the archives of your new personalized “partners” post type, simply go to yournamesite.com/partenaires/. If you can’t view the results or the browser returns a 404 error page, just go back to your WordPress dashboard, navigate to settings> permalinks, and save the permalink settings again.

Easily create custom post types

Custom post types allow you to enrich your WordPress website and can be used in a number of ways. From highlighting partner profiles to creating testimonials, products, and more, custom post types are useful and easy to create.


You can even use custom post types to build your own online business, like a web directory. Before you start, however, make sure you know how to set up a WordPress website.


how to create a stunning website
How to set up your own website in 2 hours or less

Never created a website before, but want to give it a try? Follow these steps to create your own website in just a few hours!

Read more


About the Author

Esther L. Gunn