📦 Organize Content with Custom Post Types
Blog posts are great. But what about products, portfolios, testimonials? Custom Post Types create tailored content structures.
📝 Register Custom Post Type
// functions.php
function create_post_type() {
register_post_type('book',
array(
'labels' => array(
'name' => __('Books'),
'singular_name' => __('Book')
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'books'),
'supports' => array('title', 'editor', 'thumbnail', 'excerpt'),
'menu_icon' => 'dashicons-book'
)
);
}
add_action('init', 'create_post_type');
// Flush permalinks after adding
// Go to Settings → Permalinks → Save Changes
🎯 Advanced Custom Post Types
register_post_type('portfolio',
array(
'labels' => array(
'name' => 'Portfolio',
'add_new' => 'Add New Item',
),
'public' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-portfolio',
'supports' => array('title', 'editor', 'thumbnail'),
'taxonomies' => array('category', 'post_tag'),
'has_archive' => true,
'rewrite' => array('slug' => 'portfolio-items'),
'show_in_rest' => true, // Gutenberg ready
)
);
// Custom Taxonomy for Portfolio
register_taxonomy('portfolio_type', 'portfolio',
array(
'labels' => array(
'name' => 'Types',
'add_new_item' => 'Add New Type'
),
'hierarchical' => true,
'show_in_rest' => true,
)
);
💡 Use Cases
- Products (e-commerce)
- Portfolio items
- Testimonials
- Events
- Team members
- FAQ items
- Real estate listings
“Custom Post Types organize content perfectly. Products, portfolios, testimonials — all structured. Essential for WordPress development.”
