Simply add this code to your functions.php file located in your theme folder to create a custom post type.
if ( ! function_exists('register_books') ) {
// Register our post type
function register_books() {
// Set label names for the WP backend UI
$labels = array(
'name' => _x( 'Books', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Book', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Books', 'text_domain' ),
'parent_item_colon' => __( 'Parent Book', 'text_domain' ),
'all_items' => __( 'All Books', 'text_domain' ),
'view_item' => __( 'View Book', 'text_domain' ),
'add_new_item' => __( 'Add New Book', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'edit_item' => __( 'Edit Book', 'text_domain' ),
'update_item' => __( 'Update Book', 'text_domain' ),
'search_items' => __( 'Search Book', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' )
);
// Set post type options
$args = array(
'label' => __( 'books', 'text_domain' ),
'description' => __( 'My list of books', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
'taxonomies' => array( 'category' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-book',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post'
);
register_post_type( 'books', $args );
}
add_action( 'init', 'register_books', 0 );
}