Create Custom Post Type for WordPress

Last Updated: May 11, 2020

Add this to your theme functions.php

function theme_slug_register_post_type() {
    $labels = array(
        'name'               => _x( 'Referrals', 'post type general name', 'theme-slug' ),
        'singular_name'      => _x( 'Referral', 'post type singular name', 'theme-slug' ),
        'menu_name'          => _x( 'Referrals', 'admin menu', 'theme-slug' ),
        'name_admin_bar'     => _x( 'Referral', 'add new on admin bar', 'theme-slug' ),
        'add_new'            => _x( 'Add New', 'Referral', 'theme-slug' ),
        'add_new_item'       => __( 'Add New Referral', 'theme-slug' ),
        'new_item'           => __( 'New Referral', 'theme-slug' ),
        'edit_item'          => __( 'Edit Referral', 'theme-slug' ),
        'view_item'          => __( 'View Referral', 'theme-slug' ),
        'all_items'          => __( 'All Referrals', 'theme-slug' ),
        'search_items'       => __( 'Search Referrals', 'theme-slug' ),
        'parent_item_colon'  => __( 'Parent Referrals:', 'theme-slug' ),
        'not_found'          => __( 'No Referrals found.', 'theme-slug' ),
        'not_found_in_trash' => __( 'No Referrals found in Trash.', 'theme-slug' )
    );
 
    $args = array(
        'labels'             => $labels,
        'description'        => __( 'Description.', 'theme-slug' ),
        'public'             => false,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments','page-attributes')
    );
    register_post_type( 'referral', $args );
}

 

Add your feedback or comment below: