Categories

Featured templates

WordPress. How to create a custom post type

Lana Greene January 26, 2015
Rating: 5.0/5. From 2 votes.
Please wait...

This tutorial shows how to create a custom post type in WordPress.

WordPress. How to create a custom post type

Custom post types are content types like posts and pages. Since WordPress evolved from a simple blogging platform into a robust CMS, the term post stuck to it. However, a post type can be any kind of content.

By default, WordPress comes with these post types:

  • Post

  • Page

You can create your own custom post types and call them whatever you want. For example if you run a movie review website, then you would probably want to create a movie reviews post type. This post type can have different custom fields and even its own custom category structure. Other examples of post types are: Portfolio, Testimonials, Products, etc.

In order to create custom post type in WordPress, you should do the following:

  1. Open your WordPress dashboard.

  2. Go to Appearance -> Editor. In the top right corner select themeXXXXX files to edit.

  3. Click Select button to show themeXXXXX files.

  4. Select theme-init.php file from the list shown on the screenshot below:

    Wordpress.How_to_create_custom_post_type-1

  5. In the file you will find all custom post types defined in the template.

  6. Each custom post type is highlighted with the php comment.

  7. Find the location you want to add new custom post type and paste the following code:

    /* Recipes*/
      function my_post_type_recipe() {
    	  register_post_type( 'recipe',
    	  array(
    		  'label'             => __('Recipe', CURRENT_THEME),
    		  'public'            => true,
    		  'show_ui'           => true,
    		  'show_in_nav_menus' => false,
    		  'menu_position'     => 5,
    		  'menu_icon'         => 'dashicons-book-alt',
    		  'rewrite'           => array(
    		  'slug'       => 'recipes-view',
    		  'with_front' => FALSE,
    	  ),
    	  'supports' => array(
    		  'title',
    		  'thumbnail',
    		  'editor'
    		  )
    	  )
    	  );
      }
      add_action('init', 'my_post_type_recipe');
    
  8. In our case we will add the code above the Services custom post type.

  9. Now we can see our new custom post type Recipe added:

    Wordpress.How_to_create_custom_post_type-2

  10. In order to save changes, please click Update file button.

  11. Recipe custom post type is now in your dashboard.

Now let’s change the icon for this custom post type in WordPress dashboard:

  1. Find the following line of the code added:

    'menu_icon'         => 'dashicons-visibility',
  2. dashicons-visibility is an icon code – you can replace it with another icon code;

  3. Copy the icon code:

    Wordpress.How_to_create_custom_post_type-3

  4. Replace the icon code in the file:

    Wordpress.How_to_create_custom_post_type-4

  5. Click Update file button to save the changes. The icon has been changed.

Feel free to check the detailed video tutorial below:

WordPress. How to create a custom post type

Customizable Wordpress Themes
This entry was posted in WordPress Tutorials and tagged custom, post, type, WordPress. Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket