Unwanted URL with Custom Post Type

Posted: edited May 19 at 3:36 - Source : stackoverflow

I created a custom post type. It's book and my url look like example.com/book/a-book I show books on example.com/books but there is example.com/book how can I delete that URL or show 404. In this case my sitemap shows that url: example.com/book function book_post_type() { $labels = array( 'name' => _x( 'Books', 'Post Type General Name', 'sv' ), 'singular_name' => _x( 'Book', 'Post Type Singular Name', 'sv' ), 'menu_name' => __( 'Books', 'sv' ), 'parent_item_colon' => __( 'Parent Book', 'sv' ), 'all_items' => __( 'All Books', 'sv' ), 'view_item' => __( 'View Book', 'sv' ), 'add_new_item' => __( 'Add New Book', 'sv' ), 'add_new' => __( 'Add New', 'sv' ), 'edit_item' => __( 'Edit Book', 'sv' ), 'update_item' => __( 'Update Book', 'sv' ), 'search_items' => __( 'Search Books', 'sv' ), 'not_found' => __( 'Not Found', 'sv' ), 'not_found_in_trash' => __( 'Not Found In Trash', 'sv' ), ); $args = array( 'label' => __( 'books', 'sv' ), 'description' => __( 'Books', 'sv' ), 'labels' => $labels, 'supports' => array( 'title', 'thumbnail', 'editor', 'revisions', ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => false, 'menu_position' => 5, 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'page', ); register_post_type( 'book', $args ); } add_action( 'init', 'book_post_type', 0 );