Skip to content

Instantly share code, notes, and snippets.

@BODA82
Created October 24, 2016 23:30
Show Gist options
  • Save BODA82/fe968052d9c9a3a2518a649606214b89 to your computer and use it in GitHub Desktop.
Save BODA82/fe968052d9c9a3a2518a649606214b89 to your computer and use it in GitHub Desktop.
Register WordPress Custom Post Type
<?php
if (! function_exists('gist_register_cpt')) {
/**
* Register Custom Post Type
*/
function gist_register_cpt() {
// Set CPT labels
$labels = array(
'name' => _x('Items', 'Post Type General Name', 'textdomain'),
'singular_name' => _x('Item', 'Post Type Singular Name', 'textdomain'),
'menu_name' => __('Items', 'textdomain'),
'name_admin_bar' => __('Item', 'textdomain'),
'archives' => __('Item Archives', 'textdomain'),
'parent_item_colon' => __('Parent Item' . ':', 'textdomain'),
'all_items' => __('All Items', 'textdomain'),
'add_new_item' => __('Add New Item', 'textdomain'),
'add_new' => __('Add New', 'textdomain'),
'new_item' => __('New Item', 'textdomain'),
'edit_item' => __('Edit Item', 'textdomain'),
'update_item' => __('Update Item', 'textdomain'),
'view_item' => __('View Item', 'textdomain'),
'search_items' => __('Search Items', 'textdomain'),
'not_found' => __('Not found', 'textdomain'),
'not_found_in_trash' => __('Not found in Trash', 'textdomain'),
'featured_image' => __('Featured Image', 'textdomain'),
'set_featured_image' => __('Set featured image', 'textdomain'),
'remove_featured_image' => __('Remove featured image', 'textdomain'),
'use_featured_image' => __('Use as featured image', 'textdomain'),
'insert_into_item' => __('Insert into Item', 'textdomain'),
'uploaded_to_this_item' => __('Uploaded to this Item', 'textdomain'),
'items_list' => __('Items list', 'textdomain'),
'items_list_navigation' => __('Items list navigation', 'textdomain'),
'filter_items_list' => __('Filter Items list', 'textdomain'),
);
// Set CPT args
$args = array(
'label' => __('Item', 'textdomain'),
'description' => __('Custom Items Collection', 'textdomain'),
'labels' => $labels,
'supports' => array('title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats'),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-editor-code',
'show_in_admin_bar' => false,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'rewrite' => false,
'capability_type' => 'page',
);
// Register the CPT
register_post_type('gist_post_type_key', $args);
}
add_action('init', 'gist_register_cpt', 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment