If you want to create a custom post type in WordPress without a plugin is a straightforward and simple process that does not require you to be a WordPress developer or an experienced WordPress user.
First, before we can create a custom post type without using a plugin, it helps to explain the basics of how posts work in WordPress but if you understand the basics; you can skip to this introduction section of creating custom post types.
What are Custom Post Types?
WordPress is the fastest-growing content management system but it was initially designed as a blogging CMS. It has over the years evolved to be a content management system that is used to build a robust website across all industries.
At the core of WordPress’s evolution from a blogging CMS to a full resource CMS is the custom post types.
When WordPress was designed the initial idea was to have posts and pages that could be used to publish blog posts and pages to publish static content that would not change often.
Ideally, WordPress was solving the problem of static websites by introducing a new way to easily and quickly publish new content and keep publishing more and more content without editing a single line of code.
To make WordPress more useful beyond blog publishing Custom Post Types were introduced with the aim of allowing users to create their own types of posts that could be anything they can imagine.
This custom post type allows users in diverse industries to add content to their websites that relate to their business.
Custom Post Type Example
Here is a specific example: a hotel owner can use WordPress to build the hotel website and leverage custom post types to showcase the different rooms in the hotel or the different services related to their business; standard room, single room, etc.
With this approach content published can be organized in the right way and managing the content becomes very easy.
Why Create Custom Post Types?
The overall reasons why we create custom post types are to extend the capabilities of WordPress to fit different needs.
Example: As a WordPress developer, artist, author, or creative professional, when creating a portfolio website; you cannot use the existing WordPress post and pages to showcase your work.
You can instead create a custom post type for the portfolio and use that kind of post to showcase your work and you will have better control and the appearance on your portfolio website.
Custom post types exist so that they can extend the core functionality of the website where ordinary posts and pages are limited. So now how do we create the custom post types?
How to Create Custom Post Types?
There are two major ways of creating custom post types in WordPress:
- Creating custom post types with a plugin.
- Creating custom post types without a plugin.
In this article, I will focus on the second one on how to create a custom post type in WordPress without a plugin.
First, you need to understand the basics of how to add code to your existing WordPress theme.
Creating a Custom Post Type in WordPress without Plugin
Step 1: Name of Custom Post Type
Decide the name of your custom post type. A basic example, of the custom post type for the hotel, can be rooms where we can publish the different types of rooms in that hotel with their amenities and the prices.
So we will add the name of the custom post type when we are registering it as “room”
Step 2: Register Custom Post Type
The second step is to register the custom post type in your WordPress theme.
You should add the following code to your function.php file:
//Room Custom Post Type Example add_action('init', "room_custom_post_type_example"); function room_custom_post_type_example(){ $labels = array( 'name' => _x('Rooms', 'post type general name'), 'singular_name' => _x('Room', 'post type singular name'), 'menu_name' => _x('Rooms', 'admin menu'), 'name_admin_bar' => _x('Room', 'add new on admin bar'), 'add_new' => _x('Add New', ''), 'add_new_item' => __('Add New Room'), 'edit_item' => __('Edit Room'), 'new_item' => __('New Room'), 'all_items' => __('All Room'), 'view_item' => __('View Room'), 'search_items' => __('Search Rooms'), 'not_found' => __('No Rooms found'), 'not_found_in_trash' => __('No Rooms found in Trash'), 'parent_item_colon' => __('Parent Roms:'), ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'description' => __('Description.'), 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'query_var' => true, 'rewrite' => true, 'query_var' => true, 'rewrite' => array('slug' => 'room'), 'capability_type' => 'page', 'has_archive' => true, 'menu_position' => 22, "show_in_rest" => true, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', 'page-attributes', 'custom-fields' ) ); register_post_type('room', $args); }
This code adds the custom post type to your website and it appears in your WordPress dashboard and you can now start publishing the content on your new custom post type.
You can learn more about registering custom post types.
Step 3: Publish Content on Custom Post Type
Publish your custom post type and before you can visit the front end make sure you flush the permalinks to avoid getting a 404 page not found when you check the front end.
Conclusion
With these three steps, you can easily create a custom post type in WordPress without using a plugin and begin publishing your custom content with custom templates that are specific to your custom post type.
If you are not sure about how to make this work for your website, I would like to recommend further reading on registering custom post types.
Joe is an experienced full-stack web developer with a decade of industry experience in the LAMP & MERN stacks, WordPress, WooCommerce, and JavaScript – (diverse portfolio). He has a passion for creating elegant and user-friendly solutions and thrives in collaborative environments. In his spare time, he enjoys exploring new tech trends, tinkering with new tools, and contributing to open-source projects. You can hire me here for your next project.
Similar Articles
- How to Create WooCommerce Category Loop Explained With Example
- How to Add Custom Attribute in WooCommerce
- How to Fix Duplicate WooCommerce Products Showing Up on Page
- How to Create tax_query WooCommerce Example
- WordPress Dashboard Link Not Working
- How to Get Custom Post Type in WordPress
- 25+ Best News Feed Plugins for WordPress News Sites
- WooCommerce Storefront Theme Create Multiple Category Templates
- How to Create WordPress Pagination for Custom Post Types
- How to Add Custom Post Types to ‘at Glance’ Dashboard Widget WordPress
- How to Add Submenu to Custom Post Type Menu in WordPress
- How to Use WooCommerce Save Order Hook
- How to Add Default Content to Custom Post Type Editor
- How to Remove or Hide Comments from Custom Post Type » Disable Comments in Custom Post Types
- How to Remove or Disable auto In WordPress Posts & Custom Post Types
- 5 WordPress Pagination Code Snippets with Examples [Simple to Advanced]
- How to Create Page In WordPress Programmatically
- How to Delete All Products WooCommerce MySQL
- How to Get Order ID In Woocommerce
Comments are closed.