Last active
February 4, 2020 19:18
-
-
Save omniacode/325006b4bd4853299fac43aaf2c97e7d to your computer and use it in GitHub Desktop.
Register Custom Post Type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Define Project Custom Post Type | |
* | |
* | |
*/ | |
add_action( 'init', 'register_my_custom_post_type' ); | |
function register_my_custom_post_type() { | |
$cpt_singular = 'My Custom Post Type'; | |
$cpt_plural = 'My Custom Post Types'; | |
$cpt_icon = 'dashicons-calendar'; | |
// Get Dashicons: https://developer.wordpress.org/resource/dashicons/#dashboard | |
$args = array( | |
'labels' => array( | |
"name" => $cpt_plural, | |
"singular_name" => $cpt_singular, | |
"menu_name" => $cpt_plural, | |
"all_items" => 'All ' . $cpt_plural, | |
"add_new" => 'Add New ' . $cpt_singular, | |
"add_new_item" => 'Add New ' . $cpt_singular, | |
"edit_item" => 'Edit ' . $cpt_singular, | |
"new_item" => 'New ' . $cpt_singular, | |
"view_item" => 'View ' . $cpt_singular, | |
"view_items" => 'View ' . $cpt_plural, | |
"search_items" => 'Search ' . $cpt_plural, | |
"not_found" => 'No ' . $cpt_plural . ' Found', | |
"not_found_in_trash" => 'No ' . $cpt_plural . ' found in the trash', | |
"parent_item_colon" => 'Parent ' . $cpt_singular, | |
"featured_image" => 'Featured Image for this ' . $cpt_singular, | |
"set_featured_image" => 'Set Featured Image for this ' . $cpt_singular, | |
"remove_featured_image" => 'Remove Featured Image for this ' . $cpt_singular, | |
"use_featured_image" => 'Use a Featured Image for this ' . $cpt_singular, | |
"archives" => $cpt_singular . ' Archives', | |
"insert_into_item" => 'Insert into ' . $cpt_singular, | |
"uploaded_to_this_item" => 'Upload to this ' . $cpt_singular, | |
"filter_items_list" => 'Filter ' . $cpt_plural . ' list', | |
"items_list_navigation" => $cpt_plural . ' List Navigation', | |
"items_list" => $cpt_plural . ' List', | |
"attributes" => $cpt_singular . ' Attributes', | |
"parent_item_colon" => 'Parent ' . $cpt_singular, | |
), | |
"public" => true, | |
"publicly_queryable" => true, | |
"show_ui" => true, | |
"show_in_rest" => false, | |
"rest_base" => "", | |
"has_archive" => false, | |
"show_in_menu" => true, | |
"show_in_nav_menus" => false, | |
"exclude_from_search" => false, | |
"capability_type" => "post", | |
"map_meta_cap" => true, | |
"hierarchical" => true, | |
"rewrite" => array( "slug" => "my-post-type", "with_front" => false ), | |
"query_var" => true, | |
"menu_position" => 10, | |
"menu_icon" => $cpt_icon, | |
"supports" => array( "title", "editor", "thumbnail", "excerpt", "page-attributes" ) | |
); | |
register_post_type( "my_post_type", $args ); | |
} // End CPT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment