The cart is empty

Custom Post Types (CPT) in Wordpress allow users to extend publishing capabilities and tailor the content of the website to specific needs. You can use them for e-commerce products, a portfolio of projects, a list of job offers, or any other specific content you want to distinguish from standard posts or pages. In this article, we'll show you how to create a custom post type in WordPress.

Step 1: Decide on Your Method

You can create a custom post type either by manually adding code to your theme's functions.php file or by using a plugin that simplifies this process. For beginners, we recommend using a plugin, such as Custom Post Type UI, because it minimizes the risk of errors and does not require coding.

Step 2: Manually Creating a Custom Post Type

If you prefer the manual approach, add the following code to your theme's functions.php file:

function create_custom_post_type() {
  register_post_type('your_custom_post_type',
    array(
      'labels' => array(
        'name' => __('Your Custom Posts'),
        'singular_name' => __('Your Custom Post')
      ),
      'public' => true,
      'has_archive' => true,
      'supports' => array('title', 'editor', 'thumbnail'),
    )
  );
}
add_action('init', 'create_custom_post_type');

Be sure to replace your_custom_post_type and names according to your needs.

Step 3: Using a Plugin to Create a Custom Post Type

  1. Plugin Installation: In the WordPress admin, go to Plugins > Add New. Search for "Custom Post Type UI" and install and activate the plugin.
  2. Creating a CPT: After activating the plugin, you will find a new item "CPT UI" in the admin. Go to "Add/Edit Post Types" and fill out the form to create a new custom post type. The plugin allows you to set various options, such as names, supported features, archive availability, and much more.

Step 4: Adding and Managing Content

After creating your custom post type, a new menu item will appear in the admin under which you can add and manage content just like with standard posts or pages.

Step 5: Displaying Your Custom Post Type on the Website

To display posts of your new type on the website, you will need to modify or create new template files in your theme, such as single-your_custom_post_type.php for a detailed view of a post or archive-your_custom_post_type.php for a post archive. Use the WordPress Template Hierarchy as a guide for naming these files.

 

Creating a custom post type in WordPress can help you better organize and present content on your website. Whether you decide to manually add code or use a plugin, it's important that the new post type is well thought out and serves a specific purpose on your site.