Site icon Anthony Carbon

How to add new post type?

For example I want to add a ” Home Slider ” post type. Below is the perfect codes. Just copy and paste it into your functions.php

add_action( 'init', 'home_slider_post_type' );
function home_slider_post_type() { 
	$labels = array(
		'name'               => _x( 'Home slider' ),
		'singular_name'      => _x( 'Home Slider' ),
		'menu_name'          => _x( 'Home Slider' ),
		'name_admin_bar'     => _x( 'Home Slider' ),
		'add_new'            => _x( 'Add New' ),
		'add_new_item'       => __( 'Add New' ),
		'new_item'           => __( 'New Slider' ),
		'edit_item'          => __( 'Edit Slider' ),
		'view_item'          => __( 'View Slider' ),
		'all_items'          => __( 'All Slider' ),
		'search_items'       => __( 'Search Slider' ),
		'parent_item_colon'  => __( 'Parent Home Slider:' ),
		'not_found'          => __( 'No home slider found.' ),
		'not_found_in_trash' => __( 'No home slider found in Trash.' )
	);

	$slider_array = array(
		'labels'             => $labels,
		'public'             => true,
		'publicly_queryable' => true,
		'show_ui'            => true,
		'show_in_menu'       => true,
		'query_var'          => true,
		'rewrite'            => array( 'slug' => 'home-slider' ),
		'capability_type'    => 'post',
		'has_archive'        => true,
		'hierarchical'       => false,
		'menu_position'      => 2,
		'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
	);
	register_post_type( 'home_slider', $slider_array );
}

Images that helps you to understand those arrays.



References

http://codex.wordpress.org/Function_Reference/register_post_type
http://codex.wordpress.org/Post_Types

Exit mobile version