wordpress-custom-post-workguru

Work Guru provide a Free Responsive Web Templates and Wordpress Theme. We can also customize the wordpress theme according to your needs.

If you’re a WordPress user, then you will most likely have heard of the term “Custom Post Types”. If not, then you ought to know about custom post types and why they need to be used in WordPress?

Reading this post will help you become familiar with WordPress Custom Post Types and how you can create one for your website.

A Brief on Custom Post Type

A custom post type is almost similar to a standard WordPress blog post, except that it provides a way to differentiate several content types on your WordPress website. By default WordPress contains five different post types such as:

  • Post
  • Page
  • Attachment
  • Revision
  • Navigation menu

Each of the above post type offers great functionality. But, what if you need more content types that works as per your own requirements? This can be achieved with help of WordPress Custom Post Types. They help increase the flexibility of your website and provide better control over adding specific content in your site. For instance, they help to add more categories in your blog page, or want to display posts of some particular authors and much more.

 How You Can Create Custom Post Types?

There are two different ways to create a custom post type. You can create one using a plugin, which is indeed the best way for beginners to create a custom post type (especially the ones having no programming knowledge). Custom Post Type UI is the most sought-after plugin that can be used for creating custom types. But using a plugin may not necessarily help match up to your requirements. Moreover, your custom post type(s) might no longer be visible once the plugin (i.e. the one you have used to create that custom post type) is deactivated.

So, if you have a little bit coding knowledge, you can choose to create a custom post type manually. For this purpose, you will first need to register the custom post type you want to create using the function: register_post_type().

For example, let’s say you want to create a custom post type for your automobile website named “Automobile”. In that case, you’ll have to register Automobile as your custom post type. Next, you’ll have to define an array with some parameters that will display the list of options that will be visible in your custom post type section. For doing so, add the following code to your theme’s functions.php file:

// This is your custom post type function

function create_post_type() {

register_post_type( ‘automobile’,

// Custom Post Type Options

array(

‘labels’ => array(

‘name’ => __( ‘Automobile’ ),

‘singular_name’ => __( ‘Automobile’ )

),

‘public’ => true,

‘has_archive’ => true,

‘rewrite’ => array(‘slug’ => ‘automobile’),

)

;

}

// This is a WordPress hook that ties up your function to theme setup

add_action( ‘init’, ‘create_post_type’ );

 

In this code, the array is segregated into 2 different parts. The first one includes some labels that helps to define the name of the custom post type either in singular or plural form. And the second part contains arguments, including public visibility, has_archive, and more each having a certain meaning to it, as listed below:

  • public: If you want your custom post type to become visible in your website admin panel dashboard, then set this parameter to “true”.
  • has_archive: By default, the value of this option is “false”. However, to have the ability to create post type archives, set this option to “true”.
  • Slug: defines the URLs of your post type.

Based on your needs, you can add additional options to your custom post type.

Conclusion

Here’s hoping that reading this post will help you gain knowledge about WordPress custom post types and how you can create your own post type.

Author Bio:

Jack Calder has expertise in PSD to HTML service conversion with best markup conversion service. He is a web developer & blogger and sharing web development techniques with other people on the web.

Work Guru provide a Free Responsive Web Templates and Wordpress Theme. We can also customize the wordpress theme according to your needs.

Leave a Reply

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