When it comes to building a dynamic website, WordPress Guide is your go-to resource for mastering the platform. One of the most powerful tools in WordPress is custom post types. By default, WordPress offers post types like "Posts" and "Pages," but what if your website needs to manage different types of content like portfolios, testimonials, products, or events? That’s where custom post types come in. In this WordPress Guide, we'll walk you through creating and managing custom post types, making your WordPress site more flexible and efficient.
Custom post types (CPTs) are additional content types you can add to your WordPress website to store and display different types of data. While WordPress comes pre-packaged with post types such as Posts, Pages, Attachments, and Revisions, custom post types allow you to go beyond this, creating tailored content sections. This WordPress Guide will help you understand how custom post types can make your site more organized and functional.
For example:
Using custom post types, you can manage content that doesn't fit into standard posts or pages, organizing your site better and enhancing its functionality.
Here are some key benefits highlighted in this WordPress Guide:
This WordPress Guide will walk you through all these advantages, showing how custom post types provide a solution for scaling up your content strategy.
In this WordPress Guide, we’ll explain two main ways to create a custom post type: via code and using plugins. Starting with the manual method gives you more control and a deeper understanding of WordPress’s inner workings.
functions.php
FileTo get started, navigate to your WordPress admin dashboard:
Alternatively, if you want to keep things more organized, consider creating a child theme or use a custom plugin to house your code. The WordPress Guide recommends using a child theme for long-term site maintenance.
Use the register_post_type()
function to define a new post type. Here’s an example of adding a "Portfolio" custom post type:
function create_portfolio_post_type() {
$args = array(
'labels' => array(
'name' => 'Portfolios',
'singular_name' => 'Portfolio',
'add_new' => 'Add New',
'add_new_item' => 'Add New Portfolio',
'edit_item' => 'Edit Portfolio',
'new_item' => 'New Portfolio',
'all_items' => 'All Portfolios',
'view_item' => 'View Portfolio',
'search_items' => 'Search Portfolios',
'not_found' => 'No Portfolios found',
'not_found_in_trash' => 'No Portfolios found in Trash'
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'portfolio'),
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments'),
'menu_position' => 5,
'show_in_rest' => true, // For enabling Gutenberg editor
);
register_post_type('portfolio', $args);
}
add_action('init', 'create_portfolio_post_type');
This step in the WordPress Guide outlines how to manually add a post type by coding it into your theme’s functions.php
file.
Save the changes to your functions.php
file. Now, if you go to your WordPress dashboard, you should see a new “Portfolio” option in the admin menu.
As outlined in this WordPress Guide, you can add more features or refine how the custom post type behaves. For instance, the supports
array can be extended to include custom fields or taxonomies.
If you’re not comfortable with editing code or prefer a faster route, the WordPress Guide suggests using a plugin. The most popular one for this task is Custom Post Type UI.
The WordPress Guide highlights that the plugin also provides options to set visibility, rewrite settings, and what post features to support, just like the manual method.
Once you’ve filled in all the necessary fields, click Add Post Type. Your new custom post type should now appear in the WordPress admin menu.
As this WordPress Guide explains, SEO should be kept in mind when creating custom post types to ensure visibility on search engines:
rewrite
parameter or via plugin settings.Now that you’ve successfully created a custom post type, the WordPress Guide will show you how to display it on the front-end of your site by editing your theme templates.
If you want to customize how your custom post type is displayed, the WordPress Guide recommends creating a new template file in your theme directory, such as single-portfolio.php
or archive-portfolio.php
.
In these template files, you’ll need to modify the WordPress loop to fetch and display your custom post type entries.
This WordPress Guide has walked you through creating custom post types in WordPress, offering both coding and plugin-based approaches. By following this WordPress Guide, you'll be equipped to expand your WordPress site’s content capabilities efficiently. Whether you're a beginner or an experienced developer, the flexibility of custom post types can transform how you manage content and scale your site over time.
Ready to elevate your WordPress site? Follow this WordPress Guide step by step to start adding custom post types and organizing your content like a pro!