Add new custom post type wordpress

Here are the steps to add a new custom post type in WordPress:

Step 1: Create a new file

Create a new file in the wp-content/plugins directory of your WordPress installation. For example, you can name it custom-post-type-plugin.php.

Step 2: Define the custom post type

In the new file, add the following code to define the custom post type:

<?php
/*
Plugin Name: Custom Post Type Plugin
Description: A plugin to create a custom post type
*/

function custom_post_type() {
  $labels = array(
    'name_admin_bar' => 'Custom Post Type',
    'name' => __( 'Custom Post Type' ),
    'singular_name' => __( 'Custom Post' ),
    'menu_name' => __( 'Custom Post Type' ),
    'all_items' => __( 'All Custom Posts' ),
    'add_new' => __( 'Add New Custom Post' ),
    'add_new_item' => __( 'Add New Custom Post' ),
    'edit_item' => __( 'Edit Custom Post' ),
    'new_item' => __( 'New Custom Post' ),
    'view_item' => __( 'View Custom Post' ),
    'search_items' => __( 'Search Custom Posts' ),
    'not_found' => __( 'No custom posts found' ),
    'not_found_in_trash' => __( 'No custom posts found in trash' ),
  );

  $args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'custom-post-type' ),
    'capability_type' => 'post',
    'has_archive' => true,
    'hierarchical' => false,
    'menu_position' => 5,
    'supports' => array( 'title', 'editor', 'thumbnail' ),
  );

  register_post_type( 'custom_post_type', $args );
}
add_action( 'init', 'custom_post_type' );

This code defines a custom post type called "Custom Post Type" with the following settings:

Step 3: Activate the plugin

Go to the WordPress admin dashboard and click on the "Plugins" menu. Find the "Custom Post Type Plugin" plugin and click on the "Activate" button.

Step 4: Create a new custom post

Go to the WordPress admin dashboard and click on the "Posts" menu. You should see a new menu item called "Custom Post Type". Click on this menu item to create a new custom post.

That's it! You have now created a new custom post type in WordPress.