Custom Post Type

You can create a custom post type with just these simple lines of code. This code snippet can be placed inside a custom plugin or the functions.php file in the theme. In this example the post type is called “flower”.

// Our custom post type function
function wbr_create_flower_posttype() {
 
    register_post_type( 'flower',
    // CPT Options
        array(
            'labels' => array(
                'name' => __( 'flower' ),
                'singular_name' => __( 'flower' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'flower'),
            'show_in_rest' => true,
 
        )
    );
}
// Hooking up our function to theme setup
add_action( 'init', 'wbr_create_flower_posttype' );

There are many more options available for custom post types. The key options above include public – if the post content will be available for individual display, has_archive – if there will be a dedicated archive page and show_in_rest – if the post listing will be included in rest API json.