Need to add a custom post type to your WordPress website for things like Events, Portfolios, Products, Movies etc? Here’s a nice wee template/boilerplate/code snippet that will let you add a custom post type to WordPress in seconds. This is unfinished but published due to my own needs for this custom post type template :).

Copy and paste the code snippet below into your functions.php file, and edit the Events related text to match your new custom post type. Enjoy!

function add_event_cpt() {
  $labels = array(
    'name'                  => _x( 'Events', 'Singular name' ),
    'singular_name'         => _x( 'Event', 'Plural name' ),
    'add_new'               => _x( 'Add New', 'event' ),
    'add_new_item'          => __( 'Add New Event' ),
    'edit_item'             => __( 'Edit Event' ),
    'new_item'              => __( 'New Event' ),
    'all_items'             => __( 'All Events' ),
    'view_item'             => __( 'View Event' ),
    'search_items'          => __( 'Search Events' ),
    'not_found'             => __( 'No events found' ),
    'not_found_in_trash'    => __( 'No events found in the Trash' ), 
    'parent_item_colon'     => ’,
    'menu_name'             => 'Events'
  );
  $args = array(
    'labels'                => $labels,
    'description'           => 'The post type for our company events',
    'public'                => true,
    'publicly_queryable'    => true,
    'exclude_from_search'   => false,
    'show_ui'               => true,
    'show_in_menu'          => true,
    'menu_position'         => 5,
    'menu_icon'             => 'dashicons-calendar-alt',
    'show_in_admin_bar'     => true,
    'show_in_nav_menus'     => true,
    'supports'              => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
    'has_archive'           => true,
    'rewrite'               => array('slug' => 'events'),
    'hierarchical'          => true,
    'capability_type'       => 'post',
  );
  register_post_type( 'event', $args ); 
}
add_action( 'init', 'add_event_cpt' );

You can find information about the custom post type options via the register_post_type codex.