A Definitive Tutorial To Develop WP Custom Post Types

Powering around a quarter of the complete web, WordPress is the most popular CMS available out there. This platform has amazingly blossomed into a web development tool from a blogging tool. And, a whopping number of plugins and themes (including both free and paid) heightens the credibility of the platform.

a-definitive-tutorial-to-develop-wp-custom-post-types

Isn’t it amazing how installing and activating a plugin solves great challenges while flawlessly adding desired functionalities on the site? I just love WordPress for this feature.

Though WP is an open source platform that can be managed by an individual with minimal computer knowledge, but to ensure a fresh and desired look and feel it is essential to integrate different post types, which demands efficient coding skills. Hence, it can be said that to create an out of the box website that boasts an intuitive interface with uncluttered web content and professional visual appeal the custom post types or taxonomies are musts. And, developers can help create custom post types that can lend a unique experience to viewers.

tutorial-to-develop-wp-custom-post-types

The default post types basically comprise certain elements of the WP site including Page, Post, Revision, Attachment, and Nav Menu. For a distinct visual appeal, you can create custom post types in a desired fashion and customize them to make them unique. However, while creating custom post types, it is imperative to ensure that your changes will make the navigation of your site simpler instead of complex.

How To Create Custom Post Types

There are basically two techniques of creating custom post types. Let’s first dive into the one offers an easier solution.

Custom Post Types Via a plugin

As said earlier, using an appropriate plugin can solve great challenges. Yes, you can create custom post types in a desired fashion by using a suitable plugin. Here is the step by step guide for this method.

  1. Simply install the Custom Post Type UI plugin and activate it. By doing so, a new item “CPT UI” will get added in your WP admin menu.
  2. Navigate to “CPT UI” and click on the “Add New” tab. This will allow you to create a new custom post type and custom taxonomy.
  3. For creating custom post types, you will first need to enter certain fields like the name you want to assign to your custom post type, create a label for your post type, define a singular label and provide a brief description of your new post type. Ensure that the name contains up to 20 characters and doesn’t include any space or capital letter.
  4. To further personalize the custom post type, you may click on the “Advanced Label Options” button. It will offer you more options for customization.

Though this offers an easy way out to create a desired custom post type, but there is a drawback of this approach. It is that whenever the plugin will be deactivated, unfortunately, the created custom post types will also disappear. However, the data associated with those post types would be available, but you won’t be able to access the post type from the admin area.

Manually Creating Custom Post Types

By manually adding a suitable code in the functions.php file of your theme or in the plugin, you can keep the aforementioned issue at bay.

Here is a code snippet for that creating a custom post type “recipes”.

In this code, a post type ‘recipes’ is registered with an array of arguments that include the options related to the custom post type. The array is sectioned into two parts, the first one includes labels (which are also array type) and the second part includes the rest of the arguments which will be further used in the post type’s URL.

Now, for inserting more options in the custom post type, you may add the below mentioned code chunk.

With this code, you will be able to create many more options for your custom post type, like custom fields, featured image, and many more. You can even make your custom post type to exhibit the behavior of Pages by simply setting the value of “hierarchical” to ‘true’.

How To Display The Custom Post Types

There are several methods that can be used for representing the created custom post types in a WordPress site. Here are a few of the approaches that can help you represent it seamlessly on your site.

To display the custom post types in widgets

Although in WP, the default widget represents the recent posts, but it doesn’t support the custom post types. Therefore, in order to display the recent stuff from a custom post type, you will need to follow the following steps.

  • Install the “Ultimate Posts Widget” plugin and activate it.
  • Now, navigate to the “Appearance” tab and drag the “Widgets” option in your site’s sidebar.
  • Set the requisite options for this widget and display the most recent entries for any post type with utmost ease.

Whether you want to showcase a featured image alongside the post title or provide an excerpt of the post, this plugin will let you select options as you like. Just save the changes made and see the results.

To display the custom post types on the front page

In WordPress, by default the content of the custom post types is not merged with the regular posts. However, you are interested in representing them altogether on the front page of your website, it can also be done. For this, you will need to add the below mentioned piece of code into the functions.php file of your current theme or plugin.

Code Snippet:

Here we have enabled the recent content from the custom post type “recipes” (which was created in the above section) to be displayed on the front page of the site along with the other posts from the regular post types.

By following the above mentioned steps thoroughly, you can create custom post types in your WordPress site as and when desired. Choose the options that best suits your site and make it stand ahead of the crowd with a ravishing and a unique look and feel.

Leave a Reply

50% off over 500 items. Grow your toolkit for all projects. Design, build, produce.Cyber Monday