Ask any question about WordPress here... and get an instant response.
How can I create custom post types without using a plugin in WordPress?
Asked on Dec 13, 2025
Answer
Creating custom post types in WordPress without using a plugin involves adding code to your theme's `functions.php` file. This method gives you full control over the custom post type's settings and behavior.
<!-- BEGIN COPY / PASTE -->
function my_custom_post_type() {
$labels = array(
'name' => 'Books',
'singular_name' => 'Book',
'menu_name' => 'Books',
'name_admin_bar' => 'Book',
'add_new' => 'Add New',
'add_new_item' => 'Add New Book',
'new_item' => 'New Book',
'edit_item' => 'Edit Book',
'view_item' => 'View Book',
'all_items' => 'All Books',
'search_items' => 'Search Books',
'parent_item_colon' => 'Parent Books:',
'not_found' => 'No books found.',
'not_found_in_trash' => 'No books found in Trash.'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'book'),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments')
);
register_post_type('book', $args);
}
add_action('init', 'my_custom_post_type');
<!-- END COPY / PASTE -->Additional Comment:
- Ensure you back up your theme files before making changes to `functions.php`.
- After adding the code, visit the WordPress dashboard to see the new "Books" post type.
- Remember to flush permalinks (Settings → Permalinks) after registering a new post type.
- Consider creating a child theme if you plan to modify theme files, to preserve changes during updates.
Recommended Links:
