WordPress sites can require different post types. Some will run smoothly using the default post types, while others need custom post types to better serve their content needs. If your website is the latter, this guide shows how to add a WordPress custom post type.
Tip: when setting up your website with WordPress, check out these WordPress hosting services.
How to Create a Custom Post Type in WordPress
You can easily generate a code snippet to create the custom post type you need using GenerateWP’s Post Type Generator. Paste it using a code snippet plugin, such as WPCode, a site-specific plugin, or directly to your theme’s template.
- Go to the GenerateWP Post Type Generator page, then click “General.”
- Fill out the following fields in the “General” tab:
- Function Name: the name of your custom post type.
- Child Theme: if you want the code snippet to support child themes.
- Text Domain: a unique identifier for your custom post type.
- Click “Update Code.” Remember to do this after making changes to each section.
- Every time you click “Update Code,” what you enter in the fields will be applied to the generated code snippet.
- Go to the “Post Type” section with the following fields:
- Post Type Key: key to be used in the code.
- Description: descriptive summary of the custom post type.
- Singular Name: the name of the custom post type.
- Plural Name: the name of two or more posts of the custom post type.
- Link to Taxonomies: for grouping related posts in your website.
- Hierarchical: if you want posts of this custom post type to be ordered.
- You can customize how menu items inside this custom post type will appear in the WordPress user interface in the “Labels” tab.
- Select supported items, and manage the search result appearance, exporting, and archival in the “Options” tab. Select “Update Code.”
- You can customize how the custom post type appears in your WordPress admin dashboard in the “Visibility” tab.
- Go to “Permalinks,” and select “Custom permalink” under “Permalink Rewrite” to create a custom URL slug for the custom post type. If you want posts of this type to be divided into pages, select “Yes” under “Pagination.” Select “Update Code.”
- You can manage the capabilities of users who can access the custom post type in the “Capabilities” tab.
- Highlight the generated code snippet and copy.
FYI: learn which is better: WWW or non-WWW URLs.
How to Add Code Snippets to WordPress Using WPCode
Now that you have the code snippet for your custom post type, paste it to WordPress. We’re using WPCode for ease of use.
- In your WordPress dashboard, install and activate WPCode.
- You will have a new menu item labeled “Code Snippets.”
- Hover over “Code Snippets,” then click “+ Add Snippet.”
- On the WPCode page, hover over “Add Your Custom Code (New Snippet),” then click “Use snippet.”
- Click the toggle beside “Active” to activate the snippet. Add a snippet title, select “PHP Snippet” under “Code Type,” then paste the custom post type code snippet from “GenerateWP” under “Code Preview.” Click “Save Snippet.”
- The custom post type should appear in your WordPress dashboard’s left sidebar.
Good to know: if WordPress is too complicated for you, check out these WordPress alternatives for content creation.
How to Display Custom Post Types in WordPress
If you visit your website, you may not see the menu button for the custom post type you just created. Follow the steps below to display custom post types:
- Hover over “Appearance” in your WordPress dashboard, then click “Menus.”
- You can create a new main menu or add the custom post type under an existing menu.
- Under “Add menu items,” click “Custom Links.” Add the URL slug of the custom post type you created, add the Link Text, then click “Add to Menu.”
- Select a location for the menu button under “Menu Settings.”
- Click “Save Menu” at the bottom right of the “Menus” page.
- A new menu button for the custom post type you added will be added at the menu location you selected.
Good to know: learn how to add a custom post status in WordPress.
Frequently Asked Questions
How can I view the available post types in my WordPress theme?
Easily find custom post types using the Find My Custom Post Types plugin. For viewing all registered post types, including default post types, use the get_post_types()
function. You can find the code you need in the WordPress Developer Resources page for the get_post_types()
function.
How many custom post types are there in WordPress?
You can create as many custom post types as you need, so there is no definitive number.
Is there a WordPress plugin I can use to generate custom post types?
The best free plugin for generating custom post types is Custom Post Type UI. You can also check out Pods.
Image credit: Pexels. All screenshots by Natalie dela Vega.
Our latest tutorials delivered straight to your inbox