Create Custom Post Type in WordPress

Posted: January 21, 2014 in Uncategorized

function your_function_name( )
{
// you can define your own label for your custom post type.
$labels = array(
'name' => 'PostName',
'singular_name' => 'PostName',
'add_new' => 'Add New',
'add_new_item' => 'Add New PostName',
'edit_item' => 'Edit PostName',
'new_item' => 'New PostName',
'all_items' => 'All PostName',
'view_item' => 'View PostName',
'search_items' => 'Search PostName',
'not_found' => 'No PostName found',
'not_found_in_trash' => 'No PostName found in Trash',
'parent_item_colon' => '',
'menu_name' => 'PostName'
);
$args = array(
'labels' => $labels, //your defined labels for post type
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'your-slug' // slug name for the post type
),
'capability_type' => 'post', // either it is a post or a page
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( //there you will define the nessesary things for your post type i.e post title, featured image, text editor etc
'title',
'thumbnail',
'editor'
)
);
register_post_type( 'your-slug', $args ); // this will register your post type.
}
add_action( 'init', 'your_function_name' );

Leave a comment