How to create custom post type in WordPress

Are you want to create a custom post type in your WordPress site, then this tutorial is for you. In this tutorial, i am going to explain how to create custom post type in WordPress.

This will help you create custom post types. WordPress have some default post types like post and page and WordPress also give you privileges to create unlimited post types as per your requirement. Bellow are the simple steps to create and use custom post types in your WordPress sites.

WordPress Custom Post Types

Default Post Types

Below are the lists of default post types which come up with default WordPress installation:

1) Post (Post Type: ‘post’)
2) Page (Post Type: ‘page’)
3) Attachment (Post Type: ‘attachment’)
4) Revision (Post Type: ‘revision’)
5) Navigation Menu (Post Type: ‘nav_menu_item’)
6) Custom CSS (Post Type: ‘custom_css’)
7) Changesets (Post Type: ‘customize_changeset’)

How to Create a Custom Post Type

Just assume you have a school website and you want to create a custom post type named subjects. Now open your functions.php file from your current activated theme and copy paste below snippet. This will registered a custom post type.

How to Add Custom Post Types in Main Query

If you have created a custom post type, it does not mean that it will automatically added in the main query of WordPress you have to add your custom post type in WordPress main query.
Below is the example of how to add your custom post type in main query. Copy paste

How to Add Custom Post Types to Main RSS Feed

Copy paste below code in functions.php file of your current activated theme. Below snippet will add your custom post type in main RSS feed.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

Article Tags: , , , , , ,

Comments and Discussions

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