Register a Custom Post Type in WordPress

Quick Summary
- Call register_post_type() from a function hooked to init, ideally in a child theme or custom plugin so it survives theme switches.
- With public false, the type stays out of front-end search and the Menus screen, while show_ui and publicly_queryable keep admin screens and front-end queries.
- Afterward, re-save Settings > Permalinks to avoid 404s, and add show_in_rest set to true if you want the block editor.
To add your own type of content to WordPress, such as team members, awards or testimonials, you register a custom post type. Add this code to your theme’s functions.php. A child theme or a custom plugin is the better home for it, so the post type stays registered if you switch themes.
//registering custom post
add_action( 'init', 'themename_custom_posts' );
function themename_custom_posts() {
//custom post type
register_post_type( 'name',
array(
'labels' => array(
'name' => __( 'Names' ),
'singular_name' => __( 'name' )
),
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
'public' => false,
'publicly_queryable' => true,
'show_ui' => true,
'menu_icon' => 'dashicons-awards',
)
);
}What the code does
The function runs on the init hook, which is where post types should be registered. register_post_type() takes the post type key ('name' here) and an array of settings:
labels: the plural and singular names shown in the admin.__()makes them translatable; add your text domain as its second argument.supports: the editing features the post type gets: title, content editor, featured image and page attributes (the Order field).publicisfalse, so by default the post type is left out of front-end search results and the Menus screen.show_uistill gives it admin screens, andpublicly_queryablestill allows front-end queries for it.menu_icon: the Dashicons class used for its admin menu item.
Before you use it
- Replace
'name'with your own key: lowercase letters, numbers, dashes or underscores, at most 20 characters. Update the labels to match. - The featured image box only appears if your theme supports
post-thumbnails. - If the entries should appear in search results and menus like regular posts, set
publictotrue. - After registering a new post type, re-save Settings > Permalinks so its URLs don’t return 404 errors (why new post types return 404).
- Without
'show_in_rest' => true, this post type is edited in the classic editor. Add it if you want the block editor.
Related articles
- setting up a single-{post_type}.php template: what to check when the new post type’s content doesn’t show
- letting a post type use a page template: choose a layout per entry

