In this blog, we are going to show how to create custom post type manually in WordPress. Custom post type is like a page or you can say a component just like posts, pages, etc. Before we proceed, we need to have our functions.php of our main theme. If we use child theme then we should open functions.php in any code editor.
In the file functions.php, write the following code to create a custom post type. Let us assume that we have to create custom post type named as Testimonial.
The code
/* custom post type function name */
function custom_post_type_function_name() { register_post_type('testimonial', //options array( 'labels' => array( 'name' => __('Testimonials'), 'singular_name' => __(Testimonial) ), 'public' => true, 'has_archive' => true, 'rewrite' => array('slug' => 'testimonial'), //if we need custom icon 'menu_icon' => 'dashicons-format-chat', ) ); } //invoke the function add_action('init', 'custom_post_type_function_name');
This is the basic method to create a new custom post manually. There are lots of options by which we can control our custom post type. We will discuss those options later on.
Please share if you like it.
By profession I am a Frontend Developer at Openweb Solutions.