In my previous tutorial, i introduced custom post type and its usage.

Today, i will show you how to create a simple custom post type with only the basic arguments.

To create a custom post type, you need to call the register_post_type() function. The function accepts 2 parameters, the post_type name and the arguments.

You can pass several arguments to the function like labels, public, rewrite, menu_icon, supports, and more. Please see the codex for the complete list of arguments.

The register_post_type() function can be initialized using the init add_action hook.

The example below is an example of how to create a custom post type using the most common arguments. Let’s create a post type for Portfolio.

add_action( 'init', 'register_portfolio_post_type' );
function register_portfolio_post_type() {
    $labels = array(
        'name'               => _x( 'Portfolio', 'post type general name', 'text-domain' ),
        'singular_name'      => _x( 'Portfolio', 'post type singular name', 'text-domain' ),
        'menu_name'          => _x( 'Portfolios', 'admin menu', 'text-domain' ),
        'name_admin_bar'     => _x( 'Portfolio', 'add new on admin bar', 'text-domain' ),
        'add_new'            => _x( 'Add New', 'portfolio', 'text-domain' ),
        'add_new_item'       => __( 'Add New Portfolio', 'text-domain' ),
        'new_item'           => __( 'New Portfolio', 'text-domain' ),
        'edit_item'          => __( 'Edit Portfolio', 'text-domain' ),
        'view_item'          => __( 'View Portfolio', 'text-domain' ),
        'all_items'          => __( 'All Portfolios', 'text-domain' ),
        'search_items'       => __( 'Search Portfolios', 'text-domain' ),
        'parent_item_colon'  => __( 'Parent Portfolios:', 'text-domain' ),
        'not_found'          => __( 'No portfolio found.', 'text-domain' ),
        'not_found_in_trash' => __( 'No portfolio found in Trash.', 'text-domain' )

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'rewrite'            => array( 'slug' => 'portfolio' ),
        'menu_icon'          => 'dashicons-format-quote',
        'supports'           => array( 'title', 'editor', 'thumbnail' )

    register_post_type( 'portfolio', $args );

In my next tutorials, i will show you how to create a custom post type using more arguments and with taxonomy assigned to it.