
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:
- They help keep your website tidy by separating different kinds of content.
- They make it easier for visitors to find what they’re looking for on your site.
- They let you add special features to certain posts, like review scores for book reviews.
- They can help your site show up higher in search engine results.
- 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.
- Go to your WordPress Dashboard.
- Select Plugins → Add New.
- Search for the ‘Custom Post Type UI’ 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.
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.
- Go to Add New and customize your custom post type.
- I will add a quote and contact form on my news page.
- To do that, click on the + (plus) sign.
- Select Pull Quote.
- Select Contact Form 7.
- Click on the Publish button.
- Here’s what the final news page looks like.
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.
- 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.
Go to the plugins Folder:
- Inside wp-content, find and open the plugins folder. This is where all your installed WordPress plugins reside.
Create a New Plugin Folder
- Inside the plugins directory, create a new folder named custom-post-type-plugin.
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');
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.
Activate the Plugin in WordPress
- Log into your WordPress admin dashboard.
- Go to Plugins → Installed Plugins.
- Find Custom Post Type Plugin and click Activate.
Verify the Custom Post Type
- In your WordPress admin menu, check if you see a new section labeled News.
- Click News → Add New Post to test it.
- As you can see, we can now create a new post for the new custom post type we just created.
- 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.
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.
- 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.
- 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.
- Type the excerpt and set a featured image.
- Click on the Publish button to take the new custom post live.
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.
- In the Site Editor, click on Templates in the left-hand panel.
- 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.
- Next, I’ll name my template like News Custom Template and hit Create.
- 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.
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.
- Now, if I view the newly created post, you’ll notice that it has inherited the design of the custom template we created earlier.
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:
The image below represents the final display of your listing page:
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 Appearance → Menus.
- 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.
And this is how your website will look on the front end. Check out the image below:
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.
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.
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.