What Is Custom Post Type in WordPress: Explained Simply
custom post type in WordPress is a way to create content types beyond the default posts and pages. It lets you organize and display different kinds of content, like portfolios or products, with their own structure and behavior.How It Works
Think of WordPress like a filing cabinet. By default, it has folders labeled "Posts" and "Pages" to store your content. A custom post type is like adding a new folder with a special label, for example, "Books" or "Recipes." This helps you keep different content organized and separate.
When you create a custom post type, WordPress knows to treat that content differently. It can have its own menu in the dashboard, unique settings, and even custom templates for how it looks on your site. This makes managing and displaying specialized content easier and clearer.
Example
This example shows how to register a simple custom post type called "Book" in WordPress. It will appear in the admin menu and allow you to add books as a new content type.
<?php function create_book_post_type() { $args = [ 'public' => true, 'label' => 'Books', 'menu_icon' => 'dashicons-book', 'supports' => ['title', 'editor', 'thumbnail'], ]; register_post_type('book', $args); } add_action('init', 'create_book_post_type');
When to Use
Use custom post types when you want to manage content that doesn't fit well into posts or pages. For example:
- Portfolio items for a designer
- Products in an online store
- Events or schedules
- Testimonials or reviews
This helps keep your site organized and makes it easier to build custom layouts or features for that content.
Key Points
- Custom post types extend WordPress content beyond posts and pages.
- They have their own admin menu and settings.
- They help organize and display specialized content clearly.
- Register them using
register_post_type()in your theme or plugin.