This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

📣 Introducing DigitalOceans General Purpose & CPU Optimized Servers on Cloudways Flexible. Learn More

How to Create Custom Post Types in WordPress (via Plugin and Code)

Updated on April 9, 2025

14 Min Read
wordpress custom post type

Key Takeaways:

  • WooCommerce shortcodes are a simple way to add dynamic content and functionality to your online store without needing to code.
  • They let you easily display products, categories, cart details, checkout forms, and other store elements on any page or post.
  • Using the correct shortcode and its parameters allows for customization of how these elements appear and function on your site.

When you install WordPress, you’re initially provided with five built-in content types (post types): Posts, Pages, Attachments, Revisions, and Navigation Menus.

However, as the diversity of usage increases, these standard options may not meet requirements for everyone’s needs.

To address this issue, WordPress has evolved to become more flexible and advanced. That’s where WordPress custom post types come into play. They offer a way to create and manage content that goes beyond the standard posts, pages, and media.

In this blog post, I’ll guide you through creating and managing custom post types in WordPress, from understanding their importance to troubleshooting common issues.

Let’s get started…

What Are Custom Post Types?

Custom post types in WordPress can turn your website into a powerful CMS. They allow you to create different types of content beyond the standard posts, pages, and media.

There’s no limit to the number of custom post types you can create, but managing them efficiently is important to avoid clutter and performance issues.

For instance, if you run a news website, you can create a custom post type titled “News”. This new type will have its own dedicated section in the WordPress dashboard admin area. You can create as many post types as needed, such as “Movies”, “Portfolios”, and more.

Fastest Hosting For WordPress to Handle Custom Post Types at just $11/Month*

Avoid slowdowns caused by custom post types with Cloudways’ LAMP + NGINX hybrid stack. Get blazing-fast speeds, optimized caching, seamless database performance & more.

Default vs Custom Post Types

Both default and custom post types have their own uses and can coexist on your WordPress site to provide a rich and diverse content experience. Look look at their differences!

Default Post Type Custom Post Types
Availability Available by default when you install WordPress. Need to be created manually or with a plugin.
Types Posts, Pages, and Media. Unlimited, based on your needs (e.g., News, Movies, Portfolios).
Flexibility Limited to the built-in options. Can manage posts of all users. Can publish and edit their own and others’ posts.
Usage Ideal for standard blog posts, static pages, and media files. Ideal for specialized content that doesn’t fit into the default post types.

Why Use Custom Post Types?

Here are a few more reasons why you should use custom post types in WordPress:

  1. They help keep your website tidy by separating different kinds of content.
  2. They make it easier for visitors to find what they’re looking for on your site.
  3. They let you add special features to certain posts, like review scores for book reviews.
  4. They can help your site show up higher in search engine results.
  5. They make it easier to create consistent, structured content, especially when multiple people are adding content to your site.

How to Create Custom Post Types in WordPress [3 Easy Methods]

Creating custom post types in WordPress can be done using two different methods: via plugin or manually. Each method caters to different user skills and preferences. Let’s look at them step by step.

Method 1: Create a Custom Post via Plugin

You can create a WordPress custom post type easily using the right plugin. For this article, I’ll use the Custom Post Type UI plugin to guide you through the process.

Step 1: Install and Activate the Plugin

The first step is to install and activate the plugin.

  1. Go to your WordPress Dashboard.
  2. Select Plugins Add New.
  3. Search for the ‘Custom Post Type UI’ plugin.
  4. Install and Activate the plugin.

Install and Activate the Plugin

Step 2: Set up and Configure the Plugin

Once activated, you’ll find a new menu item in the dashboard called CPT UI.

  • Click on CPT UI → Add/Edit Post Types to create a new custom post type.
  • Fill in the Post Type Slug, which is a required field and must be unique (usually a lowercase string with no spaces).
  • Add the plural and singular names for your custom post type as they will appear in the dashboard.
  • Click on the Add post type button.

Custom Post Type Dashboard

Step 3: Use Your Custom Post Type

Your new custom post type should now be visible in the WordPress Dashboard. You can start adding new content by clicking on the menu item for your custom post type.

New Custom Post Type Available on Sidebar

  • Go to Add New and customize your custom post type.

Select Add New To Add New Custom Post

  • I will add a quote and contact form on my news page.
  • To do that, click on the + (plus) sign.
  • Select Pull Quote.

Select Pull Quote Option

  • Select Contact Form 7.

Select Contact Form 7 Option

  • Click on the Publish button.
  • Here’s what the final news page looks like.

New Page Created

Struggling to Find the Right Plugins for Your WordPress Site?

Download our FREE ebook to unlock 45+ essential WordPress plugins for your site’s overall performance & security optimization.

Thank You

Your list is on it’s Way to Your Inbox.

Method 2: Creating a Custom Plugin for Custom Post Types in WordPress

If you want to register a custom post type without relying on a third-party plugin or modifying your theme’s functions.php file, creating a custom plugin is the best solution.

This method is portable, meaning your custom post type will remain intact even if you change your theme. It also keeps your functions well-organized and separate from theme-specific code, making maintenance easier.

Create a New Plugin Folder

  • Head to your WordPress installation directory and go to wp-content/plugins/.
  • If you’re using FileZilla (FTP client), connect to your website’s server by entering the FTP credentials provided by your hosting provider.

Connect To Website Server Via FTP

  • If you’re using cPanel, you can use the File Manager to access the directories directly through the web interface.

Locate the WordPress Directory:

  • Once you’re connected to your server or logged into your cPanel, go to the root directory of your WordPress installation. This is where you’ll find the main WordPress files, such as wp-config.php and wp-content.

Navigate to wp-content:

  • Inside the WordPress root folder, locate the folder named wp-content—this folder holds all your themes, plugins, and uploads.

Wp-content folder in root folder of FTP

Go to the plugins Folder:

  • Inside wp-content, find and open the plugins folder. This is where all your installed WordPress plugins reside.

Open Plugins Folder Inside wp-content

Create a New Plugin Folder

  • Inside the plugins directory, create a new folder named custom-post-type-plugin.

Create new folder custom-post-type

Create the Plugin File

  • Now, let’s create the main plugin file. Open any text editor (I’ll use Notepad).
  • Click File New and paste the following code:
<?php
/**
*Plugin Name: Custom Post Type Plugin
*Plugin URL: https://yourwebsite.com

*Description: A simple plugin to register a custom post type in WordPress

*Version: 1.0

*Author: Your Name

*Author URI: https://yourwebsite.com

*License: GPL2
*/

if(!defined('ABSPATH')){

 exit;//Prevent direct access
}

//Function to register the custom post type

function custom_post_type_news(){

 $args=array(
   'label'         =>__('News','textdomain'),
   'pbulic'        =>true,
   'supports'      =>array('title', 'editor', 'thumbnail', 'excerpt'),
   'menu_position' => 5,
   'menu_icon'     => 'dashicons-admin-site'
   'has_archive'   => true,
   'rewrite'       => array('slug' => 'news'),
);
 register_post_type('news',$args);

}

add_action('init', 'custom_post_type_news');

Plugin File Created

Upload the Plugin File

  • Move the file you just created to: wp-content/plugins/custom-post-type-plugin/
  • Drag and drop the custom-post-type.php file from your computer into this folder.

Drop the new file into custom post type plugin folder

Activate the Plugin in WordPress

WordPress Dashboard navigate to Plugins -> Installed Plugins

  • Find Custom Post Type Plugin and click Activate.

Find The CPI Plugin and Activate it

Verify the Custom Post Type

  • In your WordPress admin menu, check if you see a new section labeled News.

WordPress Dashboard Sidebar View New Custom Post Type

  • Click News Add New Post to test it.

Navigating To News Click Add New Post

  • As you can see, we can now create a new post for the new custom post type we just created.

Creating Custom News Post

  • After publishing the content for your newly created custom post type, if you see a “Page Not Found” Error”, you’ll need to refresh your Permalinks. I got this error, so I’ll show you how to refresh your Permalinks:
    • In your WordPress Dashboard, go to Settings Permalinks.
    • You don’t need to change anything here.
    • Simply click the Save Changes button. This will force WordPress to regenerate the permalink structure and recognize the new custom post-type URLs.

Test News Post

Method 3: Create WordPress Custom Post Manually

Now, let’s follow these steps to create a custom post type manually on your WordPress site:

  • Navigate to the function.php file on your theme directory.

Go To function.php in WordPress Dashboard

  • Add the following code to the function.php file.
/*Register News Post Type*/

/* Custom Post Type Start */

function create_posttype() {

register_post_type( 'news',

// CPT Options

array(

'labels' => array(

'name' => __( 'news' ),

'singular_name' => __( 'News' )

),

'public' => true,

'has_archive' => false,

'rewrite' => array('slug' => 'news'),

)

);

}

// Hooking up our function to theme setup

add_action( 'init', 'create_posttype' );

/* Custom Post Type End */
  • Once you’ve added the code, the News post type will automatically appear in your WordPress menu.

News Type Shown On WordPress Sidebar

  • When creating custom post types, it is necessary to use init for the hook in add_action(), and the register_post_type() function will take the arguments.

The steps we’ve covered so far have shown you how to register custom post types to the backend of any WordPress theme. Now, let’s move forward and learn how to add a custom post to your WordPress site.

Add a New WordPress Custom Post Type

You can add a new custom post on your WordPress site by following these steps:

  • Click registered custom post type, which in our case is News.
  • Click Add New.
  • Type the title and body of your post.

Enter title and body content of your News Post

  • Type the excerpt and set a featured image.
  • Click on the Publish button to take the new custom post live.

Custom News Test Post

When you create a custom post type like “News,” WordPress doesn’t automatically provide a front-end layout. Without a template, your News posts will appear like regular posts with no dedicated layout. This is exactly the case for us if you take a look at the screenshot above.

You’ll need to create a custom template to display them in a specific format or style. Let’s see how to do that…

Create a Template for Your News Custom Post Type Using FSE

In Full Site Editing, templates are created and assigned through the Site Editor rather than through PHP files. Since I’m using the Twenty Twenty-Four WordPress theme, which fully utilizes Full Site Editing (FSE), here’s how I’ll create a custom template for my News custom post type.

Create a Template in Full Site Editor

  • Go to the WordPress Dashboard and navigate to Appearance > Editor.

Navigate To Appearance and Select Editor

  • In the Site Editor, click on Templates in the left-hand panel.

WordPress Dashboard Selecting Templates

  • Click the Add New Template button to create a new template.
  • When the new popup appears, select the type of template you want to create. I’ll choose a Custom template.

Choosing Custom Template

  • Next, I’ll name my template like News Custom Template and hit Create.

Add a Name For New Custom Template

  • After creating the template, it will open in the editor, where you can add blocks. You’ll likely want to add blocks to display the post content, title, and featured image.
  • Once happy with the template, hit Save.

New Template Created

Your template is now created, but it’s not doing anything unless you assign it something. So, in our case, I’ll assign it to the News post type we created.

Assign the Template to Your Custom Post Type

  • To assign our template to the News custom post type, I’ll create a new post and select our new template under Post Attributes.
  • I’ll also add a post title, body content, and a featured image.
  • Once done, I’ll hit Publish.

Select The New Template Under Post Attributes

  • Now, if I view the newly created post, you’ll notice that it has inherited the design of the custom template we created earlier.

News Post With New Template

If you’re using a theme that doesn’t use Full Site Editing (FSE), you can follow the steps below.

Create the Template File Manually for Non-Full Site Editing Themes

  • Open your WordPress theme folder (where your theme files are located). You can do this using FileZilla or any other FTP tool.
  • Inside the active theme folder you’re using, create a new file and name it template-news.php. I’ll use the Twenty Nineteen theme for this example as it doesn’t support FSE. This file will display your custom post type.

Add the Template Code

  • Open the newly created file (template-news.php) in a text editor (such as Notepad) and add the following code:
<?php 
/* Template Name: News */ 

get_header(); // Includes the site header 

?>

<?php 

// Define query arguments 

$args = array( 

    'post_type'      => 'news', // Custom post type 

    'posts_per_page' => 10, // Number of posts to display ); 

);

// Create a new WP_Query instance 

$the_query = new WP_Query($args); 

?> 


<?php if ($the_query->have_posts()) : ?> 

  <?php while ($the_query->have_posts()) : $the_query->the_post(); ?> <h2><?php the_title(); ?>

    </h2> <!-- Display the post title --> 
    <div class="entry-content">
      <?php the_content(); ?> <!-- Display the post content -->
    </div>
  <?php endwhile; ?>


 <?php wp_reset_postdata(); // Reset the post data to restore the global $post object ?>

<?php else : ?>
  
  <p><?php esc_html_e('Sorry, no posts matched your criteria.', 'textdomain'); ?></p> <!-- Fallback message -->

<?php endif; ?>

<?php

get_footer(); // Includes the site footer

?>

This code fetches and displays up to 10 posts from the ‘news’ custom post type. For each post, it shows the title as a link to the individual post page and displays a short excerpt. If no posts are found, it displays a fallback message.

Assign the Template to Your Custom Post Type

After creating the template, you need to assign it to a page so WordPress knows to use it.

Follow these steps:

  • Go to your WordPress Dashboard.
  • Click Pages Add New.
  • Create a new page and name it News.
  • Find the Page Attributes section in the right-hand panel and look for the Template dropdown.
  • From the dropdown, select the News template you just created (it will show up as an option because you added the Template Name in the PHP file).
  • Click Publish to make the page live.

Refer to the image below for the visual representation of the above steps:

Assigning New Template To a Page

The image below represents the final display of your listing page:

News Listing Page Display

Add Menu for Custom Post Type

Add your custom post type as a part of the Menu options on your WordPress site by following these steps:

  • Go to your WordPress Dashboard.
  • Navigate to AppearanceMenus.
  • Add the News page to your main menu to display a navigational link to our newly created WordPress custom post type, News.

For further reference, check out the image below.

Adding Menu Option For Custom Post Type

And this is how your website will look on the front end. Check out the image below:

Front End View Of Custom Post

Troubleshooting Common Issues

When working with Custom Post Types (CPTs) in WordPress, you might encounter a few common issues. Here are the two most common issues and ways to solve them.

1. Custom Post Type Not Showing up

Sometimes, you have added the custom post type, but it doesn’t appear. The possible reasons for this can be:

  • Incorrect code.
  • Plugin conflict.

Solution

  • You need to review the code to ensure that the code is right. Take expert help to do that.
  • Try deactivating the plugins to check that none conflicts with the custom post-type plugin you’re using.

2. Problems With Permalinks

If you’re experiencing issues with permalinks related to your CPT, such as 404 errors or incorrect routing, here’s how you can fix it.

Solution

  • Go to Settings → Permalinks.
  • Click on the Save Changes button.

Permalink Problem Solution

Also, sometimes, a CPT might have the same slug as an existing page, causing conflicts. Ensure that your CPT slug is unique.

Summary

So there you have it! We’ve walked through three different ways to create custom post types in WordPress: using a plugin, creating your own custom post type plugin, and editing the functions.php file directly.

Each method has its benefits, depending on what you’re comfortable with or what suits your project best.

If you’re looking to get the most out of your custom post types, using reliable hosting for WordPress can help keep things running smoothly.

And don’t forget to check out our other blog posts for more tips on optimizing your WordPress site—like 23 easy tips to speed up your WordPress website.

If you have any questions or thoughts, feel free to comment below!

Frequently Asked Questions

Q) What is custom post type in WordPress?

A: A Custom Post Type (CPT) in WordPress is a way to store content beyond the default posts and pages. It allows you to create custom content types tailored to your site’s needs, such as portfolios, testimonials, or product listings. Custom post types can be displayed and organized in the same way as regular posts, but offer more flexibility for content management.

Q) How do I get a custom post type category in WordPress?

To assign categories to a custom post type in WordPress, first, install and activate the Custom Post Type UI plugin. After that, go to the CPT UI » Add/Edit Post Types and either create a new custom post type or edit an existing one. Within the settings, make sure to check the option for “Categories” under the taxonomies section to enable category management for your custom post type.

Q) How do I create a custom post type in WordPress without plugins?

To create a custom post type without a plugin, you can add code directly to your theme’s functions.php file. Use the register_post_type() function, which registers a new content type with a variety of options such as labels, icon, and menu position. After saving the changes, refresh your site’s admin panel, and your new custom post type will be available for use.

Q) How do I create a custom post type programmatically in WordPress?

To create a custom post type programmatically, you need to use the register_post_type() function. Add it to your theme’s functions.php file or in a custom plugin. The function takes an array of arguments, which lets you specify settings like custom labels, menu icons, and support for custom fields. This approach offers full control over your custom post type’s behavior and appearance.

Q) What are custom post type related posts in WordPress?

A: Custom post type related posts in WordPress refer to content that is linked or grouped based on specific custom post types like products, events, or portfolio items. This helps to organize your website better and makes it easier for visitors to find content relevant to their interests. Custom post types enhance the user experience by providing a more tailored and organized approach to displaying content.

Q) Is custom post type UI free?

A: Yes, Custom Post Type UI is a free plugin for WordPress. It offers an easy-to-use interface that allows users to create and manage custom post types and taxonomies without needing to write any code. It simplifies the process of organizing content and is widely used by WordPress developers and site owners.

Share your opinion in the comment section. COMMENT NOW

Share This Article

Abdul Rehman

Abdul is a tech-savvy, coffee-fueled, and creatively driven marketer who loves keeping up with the latest software updates and tech gadgets. He's also a skilled technical writer who can explain complex concepts simply for a broad audience. Abdul enjoys sharing his knowledge of the Cloud industry through user manuals, documentation, and blog posts.

×

Webinar: How to Get 100% Scores on Core Web Vitals

Join Joe Williams & Aleksandar Savkovic on 29th of March, 2021.

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Do you like what you read?

Get the Latest Updates

Share Your Feedback

Please insert Content

Thank you for your feedback!

Want to Experience the Cloudways Platform in Its Full Glory?

Take a FREE guided tour of Cloudways and see for yourself how easily you can manage your server & apps on the leading cloud-hosting platform.

Start my tour