Register custom post type WordPress [Explained] | RainaStudio

Register custom post type WordPress [Explained]

We often need to register custom post type in WordPress to meet niche content publishing system. Post type can be very useful for SEO as it enables a complete series of url options with a key slug. In this case the key slug will the post type. Apart from that it can be very helpful to have a organized website which has different type or genre of contents.

In this below code snippets we will be able to add a custom post type named ‘code’ .

We need to tell the WordPress to add our custom post type function as it initialize the request. For this we need to ‘add_action’ in ‘int’ function of WordPress.

Like this:

Custom Post type Initialization:

Now we need to construct some data as array to pass with the main WordPress register custom post type function ‘register_post_type’. This functions takes a lot of arguments to set the post type more accurately we need. But here we are looking at most common arguments of the function. You can check ‘register_post_type‘ this to know about all the arguments.

Important arguments:

labels: It store all the names can be used for operating a custom post type. Please read comment above each line in label section.

public: Takes bool value ‘true’ or ‘false’. If it’s set to ”true” then the post type content is intended to use publicly. If false then it will be intended to use by code or program or admins.

has_archive: Takes bool  Value. sets whether  the post type content should be archived or not. Default is false

menu_icon: Takes string value. You can use dashing class or a full URL for this. The icon will be shown beside the menu title of this post type.

rewrite: Means URL rewrite. Takes an array. We can simply make it array(‘slug’ => ‘code’) to set the post type slug to be ‘code’

supports: Takes an array with information for the editing support of the post from backed. array(‘title’, ‘editor’) means we ill need the title field and the editor. where ? we are writing the post        currently the word press edit post page for this code custom post type.

menu_position: Takes integer value to set the position of the menu of this particular post item. The lower you put the menu item will be upper of the left menu of WordPress dashboard.

Thanks for reading. We have covered most common arguments of the register post type function. Feel free to check out the codex if you want to create more advanced and optional post type for your website. See the codex also how register_post_typo is writen by WordPress developers. Share your thoughts or code via comment.

Editorial Staff

Editorial Staff is an in-house team of native WordPress developer and industry columnists.