Skip to content

Instantly share code, notes, and snippets.

@wpflames
Last active December 21, 2023 18:21
Show Gist options
  • Save wpflames/2b581b0551a2480e5b77d1f93cea1ea9 to your computer and use it in GitHub Desktop.
Save wpflames/2b581b0551a2480e5b77d1f93cea1ea9 to your computer and use it in GitHub Desktop.
Create a Custom Post Type in WordPress
<?php
function custom_post_types() {
// Events
register_post_type('event', array(
'public' => true,
'capability_type' => 'event',
'map_meta_cap' => true,
'show_in_rest' => true,
'has_archive' => true,
'supports' => array( 'title', 'editor', 'thumbnail'),
'rewrite' => array('slug' => 'events'),
'labels' => array(
'name' => 'Events',
'add_new_item' => 'Add New Event',
'edit_item' => 'Edit Event',
'all_items' => 'All Events',
'singular_name' => 'Event',
),
'menu_icon' => 'dashicons-calendar'
));
}
add_action('init', 'custom_post_types');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment