Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save milapdave/189640b452a2143f415c2a5bb1836276 to your computer and use it in GitHub Desktop.
Save milapdave/189640b452a2143f415c2a5bb1836276 to your computer and use it in GitHub Desktop.
Register custom post type
<?php
/**
* Short custom post type
*/
function my_theme_custom_post() {
register_post_type( 'cpt',
array(
'labels' => array(
'name' => __( 'CPTs' ),
'singular_name' => __( 'CPT' )
),
'supports' => array('title', 'editor', 'custom-fields', 'thumbnail', 'page-attributes'),
'public' => true
)
);
}
add_action( 'init', 'my_theme_custom_post' );
<?php
/**
* Registers a new post type
* @uses $wp_post_types Inserts new post type object into the list
*
* @param string Post type key, must not exceed 20 characters
* @param array|string See optional args description above.
* @return object|WP_Error the registered post type object, or an error object
*/
function prefix_register_name() {
$labels = array(
'name' => __( 'Plural Name', 'text-domain' ),
'singular_name' => __( 'Singular Name', 'text-domain' ),
'add_new' => _x( 'Add New Singular Name', 'text-domain', 'text-domain' ),
'add_new_item' => __( 'Add New Singular Name', 'text-domain' ),
'edit_item' => __( 'Edit Singular Name', 'text-domain' ),
'new_item' => __( 'New Singular Name', 'text-domain' ),
'view_item' => __( 'View Singular Name', 'text-domain' ),
'search_items' => __( 'Search Plural Name', 'text-domain' ),
'not_found' => __( 'No Plural Name found', 'text-domain' ),
'not_found_in_trash' => __( 'No Plural Name found in Trash', 'text-domain' ),
'parent_item_colon' => __( 'Parent Singular Name:', 'text-domain' ),
'menu_name' => __( 'Plural Name', 'text-domain' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'description',
'taxonomies' => array(),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => null,
'menu_icon' => null,
'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',
'excerpt',
'custom-fields',
'trackbacks',
'comments',
'revisions',
'page-attributes',
'post-formats',
),
);
register_post_type( 'slug', $args );
}
add_action( 'init', 'prefix_register_name' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment