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.

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.

create-wordpress-custom-post-type

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.

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.

Posted on July 10, 2017 | Categories: Blog