How to register a custom post type in WordPress

php function.php
/* Add a post type named projects */

add_action( 'init', function() {
    register_post_type( 'projects', [
        'label'  => 'Projects',
        'public' => true,
    ]);
});