How can I create a custom post type with its own archive page?
Asked on Oct 15, 2025
Answer
Creating a custom post type in WordPress allows you to organize content beyond the default posts and pages, and you can also create a dedicated archive page for it. This involves registering the custom post type using a function in your theme's `functions.php` file.
<!-- 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 to register the custom post type.
- Ensure 'has_archive' is set to true to enable the archive page.
- Visit "http://yourdomain.com/books" to see the archive page after registering.
- Customize the archive display by creating an `archive-book.php` template in your theme.
Recommended Links: