Word Press

How do I create a custom post type Using Function.php?

Step 1 : Open your function.php file write down below code.

function create_CUSTOM_FUNTION_NAME() {
    register_post_type( 'CUSTOM POST TYPE NAME',
        array(
            'labels' => array(
                'name' => 'CUSTOM POST TYPE NAME',
                'singular_name' => 'CUSTOM POST TYPE NAME',
                'add_new' => 'Add New',
                'add_new_item' => 'Add New CUSTOM POST TYPE NAME',
                'edit' => 'Edit',
                'edit_item' => 'Edit CUSTOM POST TYPE NAME',
                'new_item' => 'New CUSTOM POST TYPE NAME',
                'view' => 'View',
                'view_item' => 'View CUSTOM POST TYPE NAME',
                'search_items' => 'Search CUSTOM POST TYPE NAME',
                'not_found' => 'No CUSTOM POST TYPE NAME found',
                'not_found_in_trash' => 'No CUSTOM POST TYPE NAME found in Trash',
                'parent' => 'Parent CUSTOM POST TYPE NAME'
            ),
 
            'public' => true,
            'menu_position' => 15,
            'supports' => array( 'title', 'editor', 'comments', 'thumbnail', 'custom-fields' ),
            'taxonomies' => array( '' ),
            'menu_icon' => plugins_url( 'images/image.png', __FILE__ ),
            'has_archive' => true
        )
    );
}

NOTE: CUSTOM POST TYPE NAME Replace With your Custom Post type Name.

Step 2 :
Where

  • ‘public’ => true determines the visibility of the custom post type both in the admin panel and front end.
  • ‘menu_position’ => 15 determines the menu position of the custom post type.
  • ‘supports’ => array( ‘title’, ‘editor’, ‘comments’, ‘thumbnail’, ‘custom-fields’ ) determines the features of the custom post type which is to be displayed.
  • ‘taxonomies’ => array( ” ) creates custom taxonomies. Here it’s not defined.
  • ‘menu_icon’ => plugins_url( ‘images/image.png’, __FILE__ ) displays the admin menu icon.
  • ‘has_archive’ => true enables archiving of the custom post type.
  • Step 3 : Register Custom Function

     add_action( 'init', 'create_CUSTOM_FUNTION_NAME' );
    

    In Second parameter we have to pass our Custom function Name.
    Step 4 : you can see the new custom post type at admin side.

    Advertisements

    Leave your comments

    Please log in using one of these methods to post your comment:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s