WINTER SALE Get 20% OFF everything using the coupon code: FLASH20 View Pricing Plans →

How to Create Custom Post Types in WordPress

WordPress, a powerful content management system, offers incredible flexibility to organize and showcase content. However, its default post types, like posts, pages, and media, may not meet the needs of every website. This is where custom post types (CPTs) come in, enabling you to create specialized content types like portfolios, testimonials, or product catalogs.

In this guide, we’ll explore both plugin-based and manual methods to create custom post types, offering step-by-step instructions to help you unlock WordPress’s full potential for advanced content management.

How to Create Custom Post Types in WordPress

Table of Contents

  1. What Are Custom Post Types?
  2. How to Create Custom Post Types in WordPress
  3. Displaying Custom Post Types on Your Site
  4. Key Benefits of Using Custom Post Types

What Are Custom Post Types?

Custom post types (CPTs) are an essential feature in WordPress that allows you to extend your site’s functionality beyond the default options like posts, pages, and media. They provide a way to organize and manage unique content formats tailored to your specific needs, transforming WordPress from a simple blogging platform into a comprehensive content management system.

For instance, if you run a movie review website, you can create a custom post type specifically for “Movie Reviews.” Similarly, businesses can use CPTs for portfolios, testimonials, or product listings. By creating these distinct content categories, you make it easier for users to navigate your site and for search engines to index your content effectively.


Default vs. Custom Post Types

WordPress comes with several default post types designed to manage common content types. These include Posts, Pages, Media, Attachments, Revisions and Menus.

While these default types are versatile, they may not be sufficient for websites with specialized content needs. This is where custom post types (CPTs) come in, offering flexibility to organize content more precisely.

Custom post types allow unique fields, taxonomies, and templates, whereas default post types have limited customization. Default types are general-purpose, while CPTs are tailored to specific content categories (e.g., products, portfolios).

A movie review website, for instance, could use a CPT for reviews, complete with custom taxonomies for genres or ratings. Similarly, an e-commerce store might rely on WooCommerce’s product CPT to manage its inventory.


When to Use Custom Post Types

  • When your website requires content distinct from blog posts or static pages.
  • To create a unique section in the WordPress admin dashboard for better backend organization.
  • To enhance the user experience with specialized layouts and functionality for specific content types.

How to Create a WordPress Custom Post Type: Step-by-Step

Creating custom post types in WordPress can be achieved in two main ways: using a plugin or adding custom code manually. Both methods are effective, with the choice depending on your technical proficiency and project requirements.

Method 1: Using a Plugin

If coding isn’t your strong suit, or you prefer a quick and efficient method, using a plugin is the easiest way to create custom post types in WordPress. Plugins like Custom Post Type UI simplify the process, offering a user-friendly interface to configure your custom post types without touching a single line of code.

Here’s a step-by-step guide to creating custom post types using the Custom Post Type UI plugin:

Step 1. Install and Activate the Plugin

Go to your WordPress dashboard, navigate to Plugins > Add New Plugin, search for “Custom Post Type UI” in the plugin repositor, click Install Now and then Activate.

Custom Post Type UI plugin

Once activated, a new menu item labeled Custom Post Type UI will appear in your dashboard and you will be redirected to this section.

Step 2. Add a New Custom Post Type

Navigate to Custom Post Type UI > Add/Edit Post Types.

In the Add New Post Type section:

  • Post Type Slug: Enter a unique slug for your custom post type (e.g., “portfolio”). The slug will be used in URLs and must be lowercase with no spaces.
  • Plural Label: Enter the plural name for your post type (e.g., “Portfolios”).
  • Singular Label: Enter the singular name for your post type (e.g., “Portfolio”).
CTP UI: add post type

Scroll down to configure the Basic Settings, such as:

  • Visibility: Choose whether the post type will be publicly visible.
  • Capability Type: Select “post” for blog-style behavior or “page” for hierarchical behavior.
  • Enable REST API: Check this box to make the post type compatible with the Gutenberg editor.

Step 3. Configure Additional Settings

The plugin allows you to fine-tune various aspects of your custom post type. Key options include:

  • Supports: Choose the features your post type should support, such as Title, Editor, Featured Image, Custom Fields, and Comments.
  • Taxonomies: Enable categories or tags for your custom post type if needed.
  • Menu Icon: Select a dash icon or upload a custom icon for the admin menu.
  • Rewrite Rules: Customize the URL structure for your post type.
CPT UI: Settings

Step 4. Save and Verify

After configuring your settings, click the Add Post Type button.

Check your WordPress dashboard. Your new custom post type (e.g., “Portfolios”) will now appear as a menu item.

CPT UI: Portfolios custom post type

Start creating entries by navigating to Portfolios > Add new Portfolio.


Upgrade Your Website with a Premium WordPress Theme

Find a theme that you love and get a 20% discount at checkout with the FLASH20 code

Choose your theme

Method 2: Manually via Code

For developers or advanced users, manually creating custom post types offers the greatest level of flexibility. This involves adding a custom function to your theme’s functions.php file or a custom plugin.

However, directly editing your theme’s functions.php file can be risky. A single error in the code could break your site, and any changes made may be lost when updating your theme. To avoid these pitfalls, we recommend using the WPCode plugin, a safe and reliable tool for managing custom code snippets.

WPCode allows you to add custom code snippets to your WordPress site without modifying core files, ensuring your changes remain intact during updates and are easier to manage.

Steps to create a custom post type using WPCode:

Step 1. Install and Activate WPCode

Navigate to Plugins > Add New Plugin in your WordPress dashboard.

Search for “WPCode” and click Install Now and Activate.

WPCode plugin

Step 2. Access the Code Snippets Library

After activation, go to Code Snippets > Add Snippet.

WPCode add snippet

Click Add Your Custom Code (New Snippet) to create a new custom snippet.

WPCode custom code

Select PHP Snippet.

WPCode PHP snippet

Step 3. Write Your Custom Code

Give your snippet a title like “Custom Post Type – Portfolio.”

Copy and paste the following example code into the editor:

// Function to register a custom post type
function create_custom_post_type() {
	$labels = array(
    	'name'           	=> _x('Portfolios', 'Post Type General Name', 'text_domain'),
    	'singular_name'  	=> _x('Portfolio', 'Post Type Singular Name', 'text_domain'),
    	'menu_name'      	=> __('Portfolios', 'text_domain'),
    	'all_items'      	=> __('All Portfolios', 'text_domain'),
    	'add_new_item'   	=> __('Add New Portfolio', 'text_domain'),
    	'edit_item'      	=> __('Edit Portfolio', 'text_domain'),
    	'view_item'      	=> __('View Portfolio', 'text_domain'),
	);

	$args = array(
    	'label'          	=> __('Portfolio', 'text_domain'),
    	'description'    	=> __('Portfolio custom post type', 'text_domain'),
    	'labels'         	=> $labels,
    	'supports'       	=> array('title', 'editor', 'thumbnail', 'custom-fields'),
    	'public'         	=> true,
    	'has_archive'    	=> true,
    	'rewrite'        	=> array('slug' => 'portfolios'),
    	'show_in_rest'   	=> true,
	);

	register_post_type('portfolio', $args);
}

// Hook the function to the 'init' action
add_action('init', 'create_custom_post_type');

Replace “text_domain” in the code with the actual text domain of your theme to enable translations.

The text_domain placeholder is known as the “Text Domain.” If your theme is designed to support translations, including a text domain ensures that all text strings in your custom post types can be translated properly.

To locate your theme’s text domain, check the style.css file in your theme directory or navigate to Appearance > Theme File Editor in your WordPress dashboard. The text domain will be listed in the file header.

WPCode: create custom post type

Step 4. Save and Activate the Snippet

After pasting the code, click Save Snippet.

WPCode: activate custom post type

The custom code will now run automatically without modifying your theme files.

Refresh your WordPress dashboard. You should see the new Portfolios post type listed as a menu item.


Upgrade Your Website with a Premium WordPress Theme

Find a theme that you love and get a 20% discount at checkout with the FLASH20 code

Choose your theme

Displaying Custom Post Types on Your Site

Once you’ve created and customized your custom post types (CPTs), the next step is to display them effectively on your website. This involves integrating them into your theme and making them accessible to visitors through menus, widgets, and templates.

Using Default WordPress Archive Templates

When registering a custom post type, setting the has_archive parameter to true automatically creates an archive page for that post type. This page will display all the entries under the CPT in reverse chronological order using the default archive.php template.

The URL for the archive page will typically follow this format:

For example, if the slug is portfolio, the archive URL would be:

No additional setup is required to enable this functionality, making it a quick way to display your CPT entries.

The default archive.php template may not provide the desired look or functionality. For example, it might not display custom fields or tailored designs relevant to the CPT.

Custom templates are recommended to overcome these limitations.


Creating Custom Templates for Single and Archive Views

Creating custom templates provides full control over how your CPTs appear on the front end.

Custom Archive Template

Here is how to create a custom archive page:

1. In your active theme directory, create a file named archive-{post_type}.php (e.g., archive-portfolio.php).

2. Copy the content from your theme’s archive.php file into the new file.

3. Customize the layout to fit your requirements. For example:

<?php get_header(); ?>
<div class="portfolio-archive">
	<h1>Our Portfolio</h1>
	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<div class="portfolio-item">
        	<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        	<?php the_excerpt(); ?>
    	</div>
	<?php endwhile; else: ?>
    	<p>No portfolio items found.</p>
	<?php endif; ?>
</div>
<?php get_footer(); ?>

Custom Single Post Template

To display individual CPT entries in a tailored format:

1. Create a file named single-{post_type}.php (e.g., single-portfolio.php).

2. Include custom fields, metadata, and other details relevant to the CPT. Example:

<?php get_header(); ?>
<div class="portfolio-item">
	<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    	<h1><?php the_title(); ?></h1>
    	<?php if (has_post_thumbnail()) : ?>
        	<div class="portfolio-image"><?php the_post_thumbnail('large'); ?></div>
    	<?php endif; ?>
    	<p><strong>Client:</strong> <?php the_field('client_name'); ?></p>
    	<p><strong>Project Date:</strong> <?php the_field('project_date'); ?></p>
    	<div class="portfolio-content"><?php the_content(); ?></div>
	<?php endwhile; endif; ?>
</div>
<?php get_footer(); ?>

Adding Custom Post Types to Menus

Make your CPTs easily accessible by adding their archive pages to your navigation menus:

1. Go to Appearance > Menus in the WordPress admin dashboard.

Appearance - Menus

2. In the Portfolios section, click on View All to see your custom post type’s archive.

3. Select the CPT archive (e.g., “All Portfolios”) and click Add to Menu.

4. Arrange the menu item and click Save Menu.

Menus - Portfolios custom post tyoe

This method ensures users can access your CPTs directly from the main navigation.


Displaying Custom Post Types in Widgets

Widgets allow you to showcase recent CPT entries in sidebars, footers, or other widgetized areas of your website:

1. Install and activate the Custom Post Type Widgets plugin.

Custom Post Type Widgets plugin

2. Navigate to Appearance > Widgets.

Appearance - Widgets

3. Click on the “+” toogle block inserter.

Widgets - toggle block inserter

4. Drag the Recent Posts (Custom Post Type) widget into your desired widget area.

Widgets - recent posts custo post tyoe

5. Select your CPT (e.g., Portfolio) from the dropdown menu.

Widgets - custom post type portfolios

6. Configure additional settings like the number of posts to display and save your changes.

Widgets are a great way to highlight your CPT entries on multiple pages without requiring custom coding.


Key Benefits of Using Custom Post Types

  • Structured Content: Keep different types of content organized and separated, ensuring a clean backend and a logical flow for your website visitors.
  • SEO Optimization: Structured content helps search engines understand your site better, potentially improving your search rankings.
  • Enhanced User Experience: Tailored content types enable customized layouts and functionality, making your website more user-friendly.
  • Scalability: Whether you’re running a personal blog or a complex business website, CPTs can adapt to your evolving content requirements.

With these advantages, custom post types become an invaluable tool for WordPress users seeking a more organized and dynamic content structure.


Transform Your Website with WPZOOM and Custom Post Types

Ready to take your website to the next level? Explore WPZOOM’s premium themes, which are designed to integrate seamlessly with custom post types. With WPZOOM, you can create a professional, dynamic site that captivates your audience and stands out in search results. Start building your dream website today with WPZOOM!

Related Posts

Upgrade Your Website with a Premium WordPress Theme

Find a theme that you love and get a 20% discount at checkout with the FLASH20 code

Choose your theme
Subscribe to the WPZOOM newsletter.

Join 150,000 people. Get our latest news & releases delivered to your inbox.

Leave a Reply

*

*