If this tutorial is not what you were looking for, you still have any questions, suggestions or concerns - feel free to let us know. Please help us to serve you better!

Your Name

Your Email

Your Message (required)

captcha

Featured templates

WordPress. How to create a custom post type

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. Please pick an icon following this link.

  4. Copy the icon code:

    Wordpress.How_to_create_custom_post_type-3

  5. Replace the icon code in the file:

    Wordpress.How_to_create_custom_post_type-4

  6. 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