What are WordPress custom posts and how to work with them?

What are WordPress custom posts and how to work with them?

WordPress is not just a simple online platform for blogging but a whole universe that hides lots of still undiscovered little wonders. You can have a complete control over your WordPress site and you can create custom content all the time.

There are so many custom things you can add to your site you can’t even imagine. Custom post types are just a part of them.

What is a custom post type?

A custom post type is nothing more than a type of content just like pages and posts. If you take the phrase “custom post type” word by word, then it is a specific type of post that you can customize by your own liking in order to showcase certain files, elements, or items on your website. A post type can include any kind of content.

WordPress comes with a few post types by default:

  • Post
  • Page
  • Attachment
  • Revision
  • Nav Menu

But you don’t have to get stuck with these. You can create any custom posts you want and name them the way you want. For instance, Portfolio, Testimonials, Products, Deals, or Events are custom posts.
events

Why are custom post types useful?

Because people usually create a website to come with something new or personal, something that can make you different. You need to create your own sections to be able to put your best content first.

That’s why photo galleries and portfolios are essential pieces for a photographer, playlists, music albums, and discography are the always-present sections for a musician, and the menu is never missing from a restaurant’s website. They’re all each individual’s choice.
menu
Custom post types are usually made to separate your representative or “special” content from the regular one such as About me or Contact pages that everybody has on their site.

How can you create a custom post type by yourself?

Now that you found out how important a custom post type is, your next obvious question should be “Ok, but how do I add these to my site?”

Well, there are two ways.

How to easily create a custom post type

To create a custom post type in an easy way you must use a plugin. Simple and fast.

Install and activate Custom Post Type UI plugin. Right after the activation, the plugin will automatically add a new item in your WordPress admin menu. You can find it with the name of CPT UI.
custom post type ui
Click on it and then on Add New to create a custom post type. The next step is to fill the spaces in the left column.

Fill every empty space with the name of your custom post. For instance, books. After you did so, click on the “Create Custom Post Type” button and you kind of finished.

If you want to make more customizations related to your custom posts, click on Advanced Label Options and Advanced Options links.

The bad news about the plugin method is that once the plugin is deactivated or uninstalled, your custom post types will disappear. So be careful with the plugin.

Creating custom post types in code?

This method is a bit more difficult considering that you have to be a good developer to apply it. That’s why I won’t insist on it. I’ll just show you what’s the code for a custom post in its simplest form, without any customization.

function my_custom_post_product() {
$args = array();
register_post_type( ‘product’, $args );
}
add_action( ‘init’, ‘my_custom_post_product’ );

To make it look and work better, there are lots of other changes and code lines that have to be added. Usually, regular users pick the first method.

Conclusion

Custom post types are awesome. Because they let you add amazing things on your website, things that, in most cases, make the difference between an ordinary website and a well crafted one.

Author Bio

Adelina Tuca is a writer and WordPress blogger at CodeinWP. She also creates content for JustFreeThemes website. She loves sports, hiking, books, rock concerts and puts down the paper everything she finds challenging and unique.

Leave a Reply

Close Menu