Skip links
Create Custom Post Types in WordPress

Create Custom Post Types in WordPress

WordPress comes with default post types like Posts and Pages, but sometimes, you need more structured content. That’s where custom post types (CPTs) come in!

Creating custom post types in WordPress allows you to organize different types of content, such as portfolios, testimonials, events, or products. This guide will walk you through:

What a custom post type is
Types of custom post types in WordPress
How to create custom post types (with & without plugins)
Best practices for using CPTs
Frequently asked questions (FAQs)

Let’s get started! 🚀


What Is a Custom Post Type in WordPress?

A custom post type (CPT) is a content type in WordPress that extends beyond standard posts and pages. It allows you to create and manage different content structures tailored to your website’s needs.

For example, a portfolio website may need a Portfolio post type, while a real estate website may need a Property Listings post type.


Why Use Custom Post Types in WordPress?

Better Content Organization

Custom post types help separate different types of content, making management easier.

Improved User Experience

Users can navigate your site more efficiently with structured content.

Enhanced SEO

Structured content can be optimized for better rankings in search engines.

More Customization

CPTs work seamlessly with custom taxonomies and fields for deeper customization.


Types of Custom Post Types in WordPress

1. Portfolio Post Type

  • Ideal for designers, artists, or agencies to showcase work.
  • Uses a custom layout with images and descriptions.

2. Testimonials Post Type

  • Stores client feedback or reviews.
  • Can be displayed on service pages using shortcodes or widgets.

3. Events Post Type

  • Used for calendars, webinars, or meetups.
  • Supports event date, time, and location details.

4. Real Estate Listings Post Type

  • Displays property details, images, and pricing.
  • Works well with custom taxonomies like property type, location, and status.

5. WooCommerce Products Post Type

  • Automatically created by WooCommerce for eCommerce stores.
  • Includes product descriptions, prices, and categories.

6. Job Listings Post Type

  • Used for career websites.
  • Includes job descriptions, salary ranges, and application links.

How to Create Custom Post Types in WordPress

Method 1: Creating Custom Post Types with Code (No Plugin)

You can manually register a custom post type in WordPress by adding code to the functions.php file of your theme or a custom plugin.

Step 1: Add the Code in functions.php

function create_custom_post_type() {
    $args = array(
        'labels'      => array(
            'name'          => 'Portfolios',
            'singular_name' => 'Portfolio',
        ),
        'public'      => true,
        'has_archive' => true,
        'supports'    => array('title', 'editor', 'thumbnail', 'excerpt', 'comments'),
        'menu_icon'   => 'dashicons-portfolio',
    );
    register_post_type('portfolio', $args);
}
add_action('init', 'create_custom_post_type');

Step 2: Save and Refresh WordPress Permalinks

  • Go to Settings → Permalinks and click Save Changes to flush rewrite rules.

Step 3: Display Custom Post Type on Your Website

Use the following loop in a custom page template or widget:

<?php
$portfolio_query = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => 6));
if ($portfolio_query->have_posts()) :
    while ($portfolio_query->have_posts()) : $portfolio_query->the_post();
?>
        <h2><?php the_title(); ?></h2>
        <p><?php the_excerpt(); ?></p>
<?php
    endwhile;
    wp_reset_postdata();
endif;
?>

Method 2: Creating Custom Post Types with a Plugin (Easy Way)

If you don’t want to edit code, you can use a plugin like Custom Post Type UI (CPT UI).

Step 1: Install and Activate Custom Post Type UI

  • Go to Plugins → Add New, search for “Custom Post Type UI,” install, and activate it.

Step 2: Create a New Custom Post Type

  1. Go to CPT UI → Add New Post Type.
  2. Enter the Post Type Slug (e.g., portfolio).
  3. Set the Plural Name (Portfolios) and Singular Name (Portfolio).
  4. Configure supports (title, editor, thumbnail, etc.).
  5. Click Add Post Type.

Your custom post type is now ready! 🎉


Best Practices for Custom Post Types in WordPress

Keep Your Permalinks SEO-Friendly

Use a structured permalink format (/portfolio/%postname%/) for better SEO.

Use Custom Taxonomies for Organization

Create categories and tags for CPTs to improve content filtering.

Ensure Theme Compatibility

Not all themes support CPTs out of the box; ensure your theme works with them.

Optimize for Performance

Use caching and limit CPT queries to prevent slowdowns.

Secure Your Custom Post Types

Use sanitize_text_field() and wp_kses() to prevent security vulnerabilities.


Frequently Asked Questions (FAQs)

1. What happens if I delete a custom post type?

If you delete a CPT from functions.php or a plugin, all associated posts become inaccessible but remain in the database.

2. Can I use custom fields with custom post types?

Yes! Use Advanced Custom Fields (ACF) or add_meta_box() for extra data like pricing or dates.

3. How do I display a custom post type in a menu?

Go to Appearance → Menus, find your CPT under “Custom Links,” and add it to your menu.

4. Can I use a page builder with custom post types?

Yes! Elementor, Divi, and Beaver Builder allow you to design custom layouts for CPTs.

5. How do I add a custom taxonomy to my post type?

Add this code to functions.php:

function create_custom_taxonomy() {
    register_taxonomy(
        'portfolio_category',
        'portfolio',
        array(
            'label' => 'Portfolio Categories',
            'hierarchical' => true,
            'rewrite' => array('slug' => 'portfolio-category'),
        )
    );
}
add_action('init', 'create_custom_taxonomy');

6. What’s the best plugin for creating custom post types?

Custom Post Type UI is great for beginners, while Pods is ideal for advanced users needing custom fields.


Conclusion

Creating custom post types in WordPress enhances your website’s organization, usability, and SEO. Whether you code manually or use a plugin, CPTs give you the flexibility to create unique content structures like portfolios, events, job listings, and more.

By following best practices and using CPTs effectively, you can build a custom WordPress website that stands out and performs well! 🚀

Leave a comment

This website uses cookies to improve your web experience.