Creating Custom Post Types In WordPress


WordPress comes standard with three core content types – Posts, Pages and Media. When WordPress first saw Wordwide attention, these three content types were all that was needed to setup and effectively run a WordPress website.

While your stock standard WordPress site can comfortably run on these three content types, in today’s day and age WordPress has become a tad more flexible and advanced.

WordPress has not only become more diversified, but usage demands have changed the way WordPress can be setup with the addition of new content types through custom post types.

Below I will show you a step-by-step guide to creating a custom post type in WordPress.

What is a Custom Post Type?

A Custom Post Type also known as “Custom Content Types” are additional post types that can be added to your WordPress using a simple function called the register_post_type(). The function allows you to add the new post type in accordance to a number of specifics such as supported features, availability, and labels.

WordPress supports an unlimited number of Custom Post Types. You can create your own custom posts and can call them up, wherever you want. For example, if you run a Recipe website and you wish to add a custom post type titled, “Recipes”. Once created, the recipes post-type would have its own menu in the WordPress dashboard admin area.

Creating a Custom Post Type

Custom Post Types can be added to any WordPress theme. Simply open the functions.php from your WordPress theme directory and add the following code.

/* Custom Post Type Start */
function create_posttype() {
register_post_type( 'recipes',
// CPT Options
  'labels' => array(
   'name' => __( 'Recipes' ),
   'singular_name' => __( 'Recipes' )
  'public' => true,
  'has_archive' => false,
  'rewrite' => array('slug' => 'recipes'),
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
/* Custom Post Type End */

After adding this code, save your functions.php file and refresh WordPress; you should now see a new tab appear in the WordPress admin area.


When you create a custom post types, it is necessary to use init for the hook in add_action(). The register_post_type() function takes the arguments.

/*Custom Post type start*/

function cw_post_type_recipes() {

$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('Recipes', 'plural'),
'singular_name' => _x('Recipes', 'singular'),
'menu_name' => _x('Recipes', 'admin menu'),
'name_admin_bar' => _x('Recipes', 'admin bar'),
'add_new' => _x('Add Recipe', 'add new'),
'add_new_item' => __('Add New Recipe'),
'new_item' => __('New Recipe'),
'edit_item' => __('Edit Recipe'),
'view_item' => __('View Recipes'),
'all_items' => __('All Recipes'),
'search_items' => __('Search Recipes'),
'not_found' => __('No Recipes found.'),

$args = array(
'supports' => $supports,
'labels' => $labels,
'public' => true,
'query_var' => true,
'rewrite' => array('slug' => 'recipes'),
'has_archive' => true,
'hierarchical' => false,
register_post_type('recipes', $args);
add_action('init', 'cw_post_type_recipes');

/*Custom Post type end*/

Displaying the Detail Page of your new Custom Post Type

Just like a default WordPress post, your new custom post type will need its own detail page template file. To do so, add a new file called single-recipe.php which is located in your WordPress theme and then add the following code to it.

/* Start the Loop */
while (have_posts()) : the_post();
   get_template_part('template-parts/post/content', get_post_format());
endwhile; // End of the loop.

Recent Posts

Get In Touch