Ask any question about WordPress here... and get an instant response.
Post this Question & Answer:
How do I add a custom post type using WordPress code? Pending Review
Asked on Apr 16, 2026
Answer
To add a custom post type in WordPress, you can use the `register_post_type` function within your theme's `functions.php` file or a custom plugin. This function allows you to define a new content type with specific features and capabilities.
<!-- BEGIN COPY / PASTE -->
function my_custom_post_type() {
$args = array(
'labels' => array(
'name' => 'Books',
'singular_name' => 'Book'
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'books'),
'supports' => array('title', 'editor', 'thumbnail')
);
register_post_type('book', $args);
}
add_action('init', 'my_custom_post_type');
<!-- END COPY / PASTE -->Additional Comment:
- Place the code in your theme's `functions.php` file or within a custom plugin to ensure it remains active even if you change themes.
- Customize the `$args` array to fit your specific needs, such as adding support for custom fields or taxonomies.
- Remember to flush the rewrite rules by visiting the "Settings → Permalinks" page after adding a new post type.
Recommended Links:
