Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Wordpress snippet to create custom post types.
add_action( 'init', 'register_cpt_cp_name' );
function register_cpt_cp_name() {
$labels = array(
'name' => __( 'plural post type name', 'text_domain' ),
'singular_name' => __( 'single post type name', 'text_domain' ),
'add_new' => _x( 'Add New single post type name', '${4:Name}', 'text_domain' ),
'add_new_item' => __( 'Add New single post type name', 'text_domain}' ),
'edit_item' => __( 'Edit single post type name', 'text_domain' ),
'new_item' => __( 'New single post type name', 'text_domain' ),
'view_item' => __( 'View single post type name', 'text_domain' ),
'search_items' => __( 'Search plural post type name', 'text_domain' ),
'not_found' => __( 'No plural post type name found', 'text_domain' ),
'not_found_in_trash' => __( 'No plural post type name found in Trash', 'text_domain' ),
'parent_item_colon' => __( 'Parent single post type name:', 'text_domain' ),
'menu_name' => __( 'plural post type name found', 'text_domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'description',
'taxonomies' => array( 'category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
//'menu_icon' => '',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'post',
'supports' => array(
'title', 'editor', 'author', 'thumbnail',
'custom-fields', 'trackbacks', 'comments',
'revisions', 'page-attributes', 'post-formats'
),
);
register_post_type( 'cp_name', $args );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment