Add Custom Post Type


Use this snippet to add custom post types to your WordPress site. This example will add a post type called “Blogs”. It goes in the functions.php file for your theme.

<?php
function blog_post_type() {

	$labels = array(
		'name'                => _x( 'Blogs', 'Post Type General Name', 'text_domain' ),
		'singular_name'       => _x( 'Blog', 'Post Type Singular Name', 'text_domain' ),
		'menu_name'           => __( 'Blogs', 'text_domain' ),
		'name_admin_bar'      => __( 'Post Type', 'text_domain' ),
		'parent_item_colon'   => __( 'Parent Item:', 'text_domain' ),
		'all_items'           => __( 'All Posts', 'text_domain' ),
		'add_new_item'        => __( 'Add New Post', 'text_domain' ),
		'add_new'             => __( 'Add New', 'text_domain' ),
		'new_item'            => __( 'New Post', 'text_domain' ),
		'edit_item'           => __( 'Edit Post', 'text_domain' ),
		'update_item'         => __( 'Update Post', 'text_domain' ),
		'view_item'           => __( 'View Post', 'text_domain' ),
		'search_items'        => __( 'Search Post', 'text_domain' ),
		'not_found'           => __( 'Not found', 'text_domain' ),
		'not_found_in_trash'  => __( 'Not found in Trash', 'text_domain' ),
	);
	$args = array(
		'label'               => __( 'Blogs', 'text_domain' ),
		'description'         => __( 'Blogs', 'text_domain' ),
		'labels'              => $labels,
		'supports'            => array( 'title', 'editor', 'author', 'thumbnail',  ),
		'taxonomies'          => array( 'category' ),
		'hierarchical'        => false,
		'public'              => true,
		'show_ui'             => true,
		'show_in_menu'        => true,
		'menu_position'       => 5,
		'menu_icon'           => 'dashicons-media-video',
		'show_in_admin_bar'   => true,
		'show_in_nav_menus'   => true,
		'can_export'          => true,
		'has_archive'         => true,
		'exclude_from_search' => false,
		'publicly_queryable'  => true,
		'rewrite' => false,
		'capability_type'     => 'post',
		'register_meta_box_cb' => 'add_events_metaboxes'

	);
	register_post_type( 'blog', $args );

}?> 
/*--- Fancy Box --- */