{"id":39426,"date":"2015-01-26T08:28:58","date_gmt":"2015-01-26T13:28:58","guid":{"rendered":"http:\/\/www.templatemonster.com\/help\/?p=39426"},"modified":"2020-01-27T10:31:43","modified_gmt":"2020-01-27T15:31:43","slug":"wordpress-create-custom-post-type","status":"publish","type":"post","link":"https:\/\/www.templatemonster.com\/help\/wordpress-create-custom-post-type.html","title":{"rendered":"WordPress. How to create a custom post type"},"content":{"rendered":"<p>\r\n<\/p>\r\n<p>This tutorial shows how to create a custom post type in WordPress.<\/p>\r\n<p><a href=\"http:\/\/www.youtube.com\/watch?v=Nq_wPLSAYRc?width=1280&amp;height=720\" rel=\"prettyPhoto\">WordPress. How to create a custom post type<\/a><\/p>\r\n<p class=\"info-box\">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.<\/p>\r\n<p>By default, WordPress comes with these post types: <\/p>\r\n<ul class=\"list\">\r\n<li>\r\n<p>Post<\/p>\r\n<\/li>\r\n<li>\r\n<p>Page<\/p>\r\n<\/li>\r\n<\/ul>\r\n<p>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. <\/p>\r\n<p>In order to create custom post type in WordPress, you should do the following:<\/p>\r\n<ol>\r\n<li>\r\n<p>Open your WordPress dashboard.<\/p>\r\n<\/li>\r\n<li>\r\n<p>Go to <strong>Appearance -> Editor<\/strong>. In the top right corner select themeXXXXX files to edit.<\/p>\r\n<\/li>\r\n<li>\r\n<p>Click <strong> Select<\/strong> button to show themeXXXXX files.<\/p>\r\n<\/li>\r\n<li>\r\n<p>Select <strong>theme-init.php<\/strong> file from the list shown on the screenshot below:<\/p>\r\n<p><a href=\"\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-1.jpg\"><img loading=\"lazy\" src=\"\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-1-300x168.jpg\" alt=\"Wordpress.How_to_create_custom_post_type-1\" width=\"300\" height=\"168\" class=\"aligncenter size-medium wp-image-39427\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-1-300x168.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-1-150x84.jpg 150w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-1-1024x576.jpg 1024w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-1.jpg 1280w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\r\n<\/li>\r\n<li>\r\n<p>In the file you will find all custom post types defined in the template.<\/p>\r\n<\/li>\r\n<li>\r\n<p>Each custom post type is highlighted with the php comment.<\/p>\r\n<\/li>\r\n<li>\r\n<p>Find the location you want to add new custom post type and paste the following code:<\/p>\r\n<pre class=\"brush:php\">\r\n\/* Recipes*\/\r\n  function my_post_type_recipe() {\r\n\t  register_post_type( 'recipe',\r\n\t  array(\r\n\t\t  'label'             =&gt; __('Recipe', CURRENT_THEME),\r\n\t\t  'public'            =&gt; true,\r\n\t\t  'show_ui'           =&gt; true,\r\n\t\t  'show_in_nav_menus' =&gt; false,\r\n\t\t  'menu_position'     =&gt; 5,\r\n\t\t  'menu_icon'         =&gt; 'dashicons-book-alt',\r\n\t\t  'rewrite'           =&gt; array(\r\n\t\t  'slug'       =&gt; 'recipes-view',\r\n\t\t  'with_front' =&gt; FALSE,\r\n\t  ),\r\n\t  'supports' =&gt; array(\r\n\t\t  'title',\r\n\t\t  'thumbnail',\r\n\t\t  'editor'\r\n\t\t  )\r\n\t  )\r\n\t  );\r\n  }\r\n  add_action('init', 'my_post_type_recipe');\r\n<\/pre>\r\n<\/li>\r\n<li>\r\n<p>In our case we will add the code above the <strong>Services<\/strong> custom post type.<\/p>\r\n<\/li>\r\n<li>\r\n<p>Now we can see our new custom post type <strong>Recipe<\/strong> added:<\/p>\r\n<p><a href=\"\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-2.jpg\"><img loading=\"lazy\" src=\"\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-2-300x168.jpg\" alt=\"Wordpress.How_to_create_custom_post_type-2\" width=\"300\" height=\"168\" class=\"aligncenter size-medium wp-image-39428\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-2-300x168.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-2-150x84.jpg 150w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-2-1024x576.jpg 1024w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-2.jpg 1280w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\r\n<\/li>\r\n<li>\r\n<p>In order to save changes, please click <strong>Update file<\/strong> button.<\/p>\r\n<\/li>\r\n<li>\r\n<p>Recipe custom post type is now in  your dashboard.<\/p>\r\n<\/li>\r\n<\/ol>\r\n<p>Now let&#8217;s change the icon for this custom post type in WordPress dashboard:<\/p>\r\n<ol>\r\n<li>\r\n<p>Find the following line of the code added:<\/p>\r\n<pre class=\"brush:php\">'menu_icon'         =&gt; 'dashicons-visibility',<\/pre>\r\n<\/li>\r\n<li>\r\n<p><strong>dashicons-visibility<\/strong> is an icon code &#8211; you can replace it with another icon code;<\/p>\r\n<\/li>\r\n<li>\r\n<p>Copy the icon code:<\/p>\r\n<p><a href=\"\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-3.jpg\"><img loading=\"lazy\" src=\"\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-3-300x171.jpg\" alt=\"Wordpress.How_to_create_custom_post_type-3\" width=\"300\" height=\"171\" class=\"aligncenter size-medium wp-image-39429\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-3-300x171.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-3-150x85.jpg 150w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-3.jpg 840w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\r\n<\/li>\r\n<li>\r\n<p>Replace the icon code in the file:<\/p>\r\n<p><a href=\"\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-4.jpg\"><img loading=\"lazy\" src=\"\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-4-300x168.jpg\" alt=\"Wordpress.How_to_create_custom_post_type-4\" width=\"300\" height=\"168\" class=\"aligncenter size-medium wp-image-39430\" srcset=\"https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-4-300x168.jpg 300w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-4-150x84.jpg 150w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-4-1024x576.jpg 1024w, https:\/\/www.templatemonster.com\/help\/wp-content\/uploads\/2014\/10\/Wordpress.How_to_create_custom_post_type-4.jpg 1280w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\r\n<\/li>\r\n<li>\r\n<p>Click <strong>Update file<\/strong> button to save the changes. The icon has been changed.<\/p>\r\n<\/li>\r\n<\/ol>\r\n<p>Feel free to check the detailed video tutorial below:<\/p>\r\n<p><a href=\"http:\/\/www.youtube.com\/watch?v=Nq_wPLSAYRc?width=1280&amp;height=720\" rel=\"prettyPhoto\">WordPress. How to create a custom post type<\/a><\/p>\r\n<\/p>\r\n<p><\/p>","protected":false},"excerpt":{"rendered":"<p>This tutorial shows how to create a custom post type in WordPress.<\/p>\n","protected":false},"author":60,"featured_media":43292,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[728],"tags":[789,592,1159,2405],"_links":{"self":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/39426"}],"collection":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/users\/60"}],"replies":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/comments?post=39426"}],"version-history":[{"count":3,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/39426\/revisions"}],"predecessor-version":[{"id":85637,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/posts\/39426\/revisions\/85637"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media\/43292"}],"wp:attachment":[{"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/media?parent=39426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/categories?post=39426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.templatemonster.com\/help\/wp-json\/wp\/v2\/tags?post=39426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}