How to Use WordPress Custom Post Types to Create a Specialty Website

After you launch a WordPress website, you can use built-in post types to organize your content. This makes it easy to create a chronological blog or display static pages. However, your website may need a more specific format than a standard page or post.

Fortunately, you can develop custom post types to create a space on your website for particular content. For specialty websites, these post types can enable creating pages that are built for specific purposes that are not available by default.

In this post, we’ll discuss what post types are and why you might consider creating your own. Then, we’ll show you how to implement them in WordPress using two methods. 

An Introduction to Post Types in WordPress

Since WordPress can host different types of content, post types are used as an organization method. As a website owner, you’ll likely be familiar with two frequently used post types: pages and posts. 

Posts are entries that are published inreverse chronological order. They enable you to share new content with your readers, and many website owners use this post type to turn their sites into blogs:

Unlike posts, pages display static content that isn’t listed by date. You can use pages to display permanent information on your website, such as creating an About page or listing contact details:

However, posts and pages are not the only types of content in WordPress. Here are some more default post types:

  • Attachments
  • Revisions
  • Navigation menus
  • Custom CSS
  • Changesets

An attachment is a piece of media that you upload to your website. This includes images, videos, or PDF files. When you upload an attachment, its unique ID and metadata are stored in your database.

Navigation menus are lists of links that visitors can use to find information on your website. You can use a menu to direct users to specific posts or pages.

Meanwhile, revisions are saved versions of any post type. Similar to revisions, changesets keep track of changes made in the Customizer.

Lastly, custom CSS is a post type that you can use to customize your WordPress theme. Adding custom coding can modify the appearance and layout of your site. 

Why You Might Consider Using Custom Post Types

While the default post types can cover a wide range of content, they may not be designed for the content you had in mind. To break down your content into more specific categories, consider creating your own custom post types.

For instance, if you’re running a specialty website such as an online store, you’ll likely need a way to group your products in one place. With a custom post type, you can include additional information such as price, color, and size:

Here’s some additional information you can display with custom post types:

Although you can organize your posts by assigning categories, this typically keeps them within the same Posts section. By creating custom post types, you can classify your content more efficiently.

How to Use Custom Post Types to Create a Specialty Website

Custom post types can help you organize your specialty website. There are different ways you can implement them. In this tutorial, we’ll walk you through two main methods.

1. Create a Custom Post Type With a Plugin

One of the easiest ways to create a post type is by installing a plugin. For example, WooCommerce comes with a custom Products post type:

This way, you won’t have to manually create a custom post type for your products. As a beginner, this can be an effective, simple way to organize your online store.

Similar to WooCommerce, The Events Calendar automatically sets up a custom post type after installation. This plugin creates a post type for events:

Some plugins are designed to make it easier to register your own custom post types. For instance, Custom Post Type UI enables you to go through this process in an admin screen, rather than editing core WordPress files and potentially breaking your site.

To do this, start by installing and activating the plugin. Then, navigate to CPT UI > Add/Edit Post Types:

At the top of this page, you can add the Post Type Slug, which is the label that will appear in the URL and in queries. This should only contain letters and numbers. For this example, we’ll use “products”:

Then, enter the post type as a plural and singular label. When you’re finished, click on Populate additional labels based on chosen labels. This will automatically create entries for the Additional labels section:

Next, scroll down to the Settings section. Here, you can choose to display the post type in navigation menus. You can also make these posts hierarchical:

Finally, you can choose the editing features you want this post type to support. You can also select Categories and Tags to make it easier for visitors to browse these posts:

When you’re ready, click on Add Post Type. This will create a new section on your WordPress dashboard, where you can create new posts for that type.

2. Manually Code a Custom Post Type

Although using a plugin can be the simplest option, you’ll lose your custom post types if you decide to deactivate it. To avoid this, consider adding custom code to your theme’s functions.php file. This can also be beneficial if you’re worried about potential plugin conflicts.

Before editing any core files, you’ll need to back up your website. This way, if something goes wrong, you can restore your site.

Once you’ve backed up your site, you’ll need to access its files through a File Transfer Protocol (FTP) client or cPanel. In this tutorial, we’ll be using a cPanel account. 

Once you’ve connected to your site, navigate to the public_html folder and open wp-content:

Next, click on themes. This will pull up a list of the installed themes on your website. Check to see which theme is currently active and open its corresponding file:

Then, look for the functions.php file. Although you can edit this file directly, you might make a mistake that crashes your site. Therefore, we recommend that you make a copy of it. Right-click on the file and select Copy:

Now, you’ll need to give the file a name. You can keep the same label and just add “backup”:

Next, open your functions.php file, scroll to the bottom, and enter the following code:

// Our custom post type function

function create_posttype() {

    register_post_type( ‘movies’,

    // CPT Options

        array(

            ‘labels’ => array(

                ‘name’ => __( ‘Movies’ ),

                ‘singular_name’ => __( ‘Movie’ )

            ),

            ‘public’ => true,

            ‘has_archive’ => true,

            ‘rewrite’ => array(‘slug’ => ‘movies’),

            ‘show_in_rest’ => true,

        )

    );

}

// Hooking up our function to theme setup

add_action( ‘init’, ‘create_posttype’ );

Your file should now look something like this:

Remember to edit this code to meet the needs of your specific post type. If you leave this code as is, it will create a post type called “Movies”. Once you’ve saved these changes, you can start adding content to the new post type in your WordPress dashboard.

How Will You Use Custom Post Types?

Using custom post types, you can expand the functionality of WordPress beyond its default posts and pages. This can be ideal for specialty websites that need to display organized portfolios, event details, product information, and more. 

To recap, here are two ways you can add custom post types to your specialty website:

  1. Use a plugin such as Custom Post Type UI.
  2. Add code to your functions.php file.

Now, try creating custom post types of your own, and see what you can achieve.

ABOUT THE AUTHOR

The WordPress.com Team

We're a team of happiness engineers, developers, editors, and WordPress experts. Our team personally curates and serves up the best resources to help you no matter where you are in your blogging or website-building journey. At WordPress.com, our mission is to democratize publishing one website at a time. Create a free website or build a blog with ease on WordPress.com. Dozens of free, customizable, mobile-ready designs and themes.

More by The WordPress.com Team