How to make a custom post type in wordpress ?
To create a custom post type in WordPress, you can use the register_post_type() function. Here are the steps to create a custom post type:
- Create a new plugin or add the code to your theme’s functions.php file.
- Use the register_post_type() function to create a new custom post type.
function create_custom_post_type() {
register_post_type( 'custom_post_type',
array(
'labels' => array(
'name' => __( 'Custom Post Type' ),
'singular_name' => __( 'Custom Post Type' )
),
'public' => true,
'has_archive' => true,
)
);
}
add_action( 'init', 'create_custom_post_type' );
3. Replace ‘custom_post_type’ in the code with the desired name for your custom post type.
4. Replace ‘Custom Post Type’ in the ‘labels’ array with the desired name for your custom post type in the WordPress admin.
5. You can also add custom taxonomies, custom fields, etc.
6. Save the changes and activate the plugin or refresh your site.
The custom post type will now be available in the WordPress admin under the “Posts” menu. It is recommended to test the changes on a development environment before pushing it to live site and also take a backup of your site before making any changes.