Skip to content

Instantly share code, notes, and snippets.

@JiveDig
Last active December 17, 2015 04:19
Show Gist options
  • Save JiveDig/5550031 to your computer and use it in GitHub Desktop.
Save JiveDig/5550031 to your computer and use it in GitHub Desktop.
Register custom post type, with Videos as the example
<?php
// Register 'Videos' Post Type
if ( ! function_exists('jivedig_videos_post_type') ) {
function jivedig_videos_post_type() {
$labels = array(
'name' => _x( 'Videos', 'executive' ),
'singular_name' => _x( 'Video', 'executive' ),
'menu_name' => __( 'Videos', 'executive' ),
'parent_item_colon' => __( 'Parent Video:', 'executive' ),
'all_items' => __( 'All Videos', 'executive' ),
'view_item' => __( 'View Video', 'executive' ),
'add_new_item' => __( 'Add New Video', 'executive' ),
'add_new' => __( 'New Video', 'executive' ),
'edit_item' => __( 'Edit Video', 'executive' ),
'update_item' => __( 'Update Video', 'executive' ),
'search_items' => __( 'Search Videos', 'executive' ),
'not_found' => __( 'No Videos found', 'executive' ),
'not_found_in_trash' => __( 'No Videos found in Trash', 'executive' ),
);
$rewrite = array(
'slug' => 'videos',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __( 'videos', 'executive' ),
'description' => __( 'Videos section of website', 'executive' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'comments' ),
/* 'taxonomies' => array( 'category', 'post_tag' ), */
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
/* 'menu_icon' => '', */
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => 'videos',
'rewrite' => $rewrite,
'capability_type' => 'page',
);
register_post_type( 'videos', $args );
}
// Hook into the 'init' action
add_action( 'init', 'jivedig_videos_post_type', 0 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment