A WordPress website can contain multiple content types, known as "post types" in the WordPress world. The default post types are "Post" and "Page", but you can create your own custom post types.
On my website I've created a Code Snippets post type and a Projects post type. This simplifies the content creation process by grouping different types of content in the backend, and lets you have dynamic archives. I can customize the edit screen with Custom Metaboxes and Taxonomies .
Registering a post type
In your core functionality plugin , use the register_post_type() function to create a post type.
https://gist.github.com/billerickson/a37d53b7004b3c86379c500f73828303
Labels
The labels parameter lets you customize all the labels used throughout the WordPress backend. It's usually as simple as find/replacing the plural and singular forms of the post type, but you may want to tweak some of the other labels more extensively.
Supports
The supports parameter lets you specify which WordPress features should be enabled for this post type. Options:
- 'title'
- 'editor' (content)
- 'author'
- 'thumbnail' (featured image, current theme must also support post-thumbnails )
- 'excerpt'
- 'trackbacks'
- 'custom-fields'
- 'comments' (also will see comment count balloon on edit screen)
- 'revisions' (will store revisions)
- 'page-attributes' (menu order, hierarchical must be true to show Parent option)
- 'post-formats' add post formats, see Post Formats
Show in REST
The show_in_rest parameter lets you decide if this post type should be visible in the REST API. This must be set to true if you'd like to use the new Gutenberg block editor
Has Archive
The has_archive parameter enables the post type archive, a dynamic archive listing recent content in this post type.
Rewrite
The rewrite parameter lets you enable and customize the URL rewriting for this content type.
Menu Icon
The menu_icon parameter lets you specify a Dashicon to use as the icon in the admin area.
Using a plugin
Rather than coding it yourself, you can use Custom Post Type UI to create and manage your custom post types. The plugin lets you specify the post type slug, labels, and settings shown above.
No comments yet