Create new custom post type – WordPress

Ideally you should create a plugin when working with custom post types, but if you don’t know how, or just need a quick test, you can use the functions.php file in your theme.

add_action( 'init', 'software_download' );
    function software_download() {
    register_post_type( 'software_download', array() );

In its simplest form, it will create a post type which has almost no customization. It won’t be public, it won’t show up in the admin, interaction messages will be the same as posts (“post saved,” “post updated,” etc.) and so on. To tailor our new post type to our needs, I’ll go through some of the more frequently-used options and add them to the previously empty  array.

add_action( 'init', 'software_download' );
    function software_download() {
    register_post_type( 'software_download',
            'labels' => array(
                'name' => 'Download',
                'singular_name' => 'Download',
                'add_new' => 'Add New',
                'add_new_item' => 'Add New Download',
                'edit' => 'Edit',
                'edit_item' => 'Edit Movie Download',
                'new_item' => 'New Movie Download',
                'view' => 'View',
                'view_item' => 'View Movie Download',
                'search_items' => 'Search Downloads',
                'not_found' => 'No Downloads found',
                'not_found_in_trash' => 'No Downloads found in Trash',
                'parent' => 'Parent Downloads'
            'public' => true,
            'menu_position' => 15,
            'supports' => array( 'title', 'editor', 'comments', 'thumbnail' ),
            'taxonomies' => array( '' ),
            'menu_icon' => plugins_url( 'images/arrow.png', __FILE__ ),
            'has_archive' => true

The register_post_type function does most of the work for us. As soon as it is called it prepares the WordPress environment for a new custom post type including the different sections in the admin. This function takes two arguments: the first one is an unique name of the custom post type and the second one an array demonstrating the properties of the new custom post type.

The second parameter is an array of arguments:

  • 'labels'
    labels option should be an array defining the different labels that a custom post type can have. I have separated this out above just to make the arguments for registering a post type clearer.
  • '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.

Please visit the WordPress Codex register_post_type page for more details on the different arguments used in custom post types.


Or try this


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your 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