{"id":4552,"date":"2018-06-22T14:59:46","date_gmt":"2018-06-22T14:59:46","guid":{"rendered":"https:\/\/www.inmotionhosting.com\/support\/2018\/06\/22\/add-custom-post-type-to-your-theme-functions-file\/"},"modified":"2021-08-16T22:27:02","modified_gmt":"2021-08-17T02:27:02","slug":"add-custom-post-type-to-your-theme-functions-file","status":"publish","type":"post","link":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/","title":{"rendered":"Add Custom Post Type to Your Theme Functions File"},"content":{"rendered":"<div class=\"alert alert-warning\" role=\"alert\">     This article references the <a href=\"\/support\/edu\/wordpress\/how-to-make-a-custom-post-type\/\">Custom Post Type UI<\/a> plugin. <\/div>\n<p>You may recall in our previous article on custom post types (linked above) how we can create one or many custom post types easily with the Custom Post Type UI plugin. But you don&#8217;t need a plugin to create custom post types, it just makes the process easier by adding a user interface.<\/p>\n<p>Once you have the code, custom post types can be incorporated into your theme (whether you&#8217;re using a custom theme or a <a href=\"https:\/\/codex.wordpress.org\/Child_Themes\">child theme<\/a>).In this article, we&#8217;ll show you how you can <strong>custom post types<\/strong> created in the Custom Post Type UI plugin and add them to your theme. <\/p>\n<h2 id=\"orgefb04df\">A Few Simple Facts<\/h2>\n<p>          In order to accomplish the goals in this article, we will cover a few           simple facts:           <\/p>\n<ul class=\"org-ul\">\n<li>Why this is important<\/li>\n<li>Where the code goes<\/li>\n<li>How to copy code from the CPT UI plugin<\/li>\n<li>How to copy the code to your <code>functions.php<\/code> file<\/li>\n<\/ul>\n<p>          That&#8217;s all we&#8217;ll need to do!            <\/p>\n<h2 id=\"orgbc95886\">Why Is This Important?<\/h2>\n<p>            In essence, this article will explain how you can take code created by          a plugin and incorporate it into your theme so you don&#8217;t need the           plugin. There are many reasons why you might want to do this:           <\/p>\n<ul class=\"org-ul\">\n<li>More control over your code<\/li>\n<li>Fewer plugins to manage<\/li>\n<li>Reduced complexity<\/li>\n<\/ul>\n<p>            By incorporating code from a plugin into a theme, you reduce the            overall complexity of your site. However, there may always be plugins           which are performing many important functions on your site, and you             would be best advised to keep those running as they are.            <\/p>\n<p>            But, in the case of this article, we&#8217;re working with a plugin that          only creates and edits custom post types, which we can easily bring             into a theme. Once you&#8217;ve created all the custom post types you             require, there&#8217;s no need to keep the plugin installed on your site.             <\/p>\n<h2 id=\"orgb27a9aa\">Where Does the Code Go?<\/h2>\n<p>           In this article, we&#8217;re focusing on the theme and assuming you use a             custom theme or a child theme. In that case, we will be using a theme           file called <code>functions.php<\/code>. This is a special file WordPress uses to           run custom PHP functions associated with your theme.            <\/p>\n<p>            First, we will need to access raw PHP code produced by the Custom Post          Type UI plugin.             <\/p>\n<h2 id=\"org7f072cc\">How to Copy Code From Custom Post Type UI<\/h2>\n<p>             Now we will extract the PHP code for our custom post type from the          plugin.             <\/p>\n<ol class=\"article_list\">\n<li>Log into your WordPress Dashboard<\/li>\n<li>Click <b>Tools<\/b> under <i>CPT UI<\/i> (left panel)<\/li>\n<li>Choose the <b>Get Code<\/b> tab at the top<\/li>\n<\/ol>\n<p>             Which code should you copy? If you created multiple custom post types,          you will want to copy the code under <i>All CPT UI Post Types<\/i>. If you           only require one custom post type, you will see it listed under its             own section.            <\/p>\n<h2 id=\"orgb77d91e\">Copy the Code into the Functions File<\/h2>\n<div class=\"alert alert-warning\" role=\"alert\">          You are best advised to edit WordPress files in a development environment           \u2014 not a <em>production<\/em>, or, live server environment.           <\/div>\n<p>          Now, you will only need to open your <code>functions.php<\/code> file in your           theme directory:            <\/p>\n<p> <code>\/wp-content\/themes\/custom-theme-name\/functions.php<\/code> <\/p>\n<p>           In most cases, it is considered safe to begin a PHP block without           closing it:             <\/p>\n<div class=\"org-src-container\">\n<pre class=\"src src-php\"><span style=\"color: #483d8b;\">&lt;?php<\/span> <span style=\"color: #b22222;\">\/\/ <\/span><span style=\"color: #b22222;\">The Custom Post Type code pasted here<\/span> <span style=\"color: #b22222;\">\/\/ <\/span><span style=\"color: #b22222;\">...<\/span> <\/pre>\n<\/p><\/div>\n<p>           With the PHP code for your custom post type added to the            <code>functions.php<\/code> file, make sure to save the file. Also, make            sure to disable the Custom Post Type UI plugin to avoid duplicate           custom post types.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article references the Custom Post Type UI plugin. You may recall in our previous article on custom post types (linked above) how we can create one or many custom post types easily with the Custom Post Type UI plugin. But you don&#8217;t need a plugin to create custom post types, it just makes the<a class=\"moretag\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/\"> Read More ><\/a><\/p>\n","protected":false},"author":17,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[56],"tags":[],"class_list":["post-4552","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Add Custom Post Type to Your Theme Functions File | InMotion Hosting<\/title>\n<meta name=\"description\" content=\"In this article, we&#039;re going to continue with custom post types and show you how to bring them into your theme.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Add Custom Post Type to Your Theme Functions File | InMotion Hosting\" \/>\n<meta property=\"og:description\" content=\"In this article, we&#039;re going to continue with custom post types and show you how to bring them into your theme.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/\" \/>\n<meta property=\"og:site_name\" content=\"InMotion Hosting Support Center\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/inmotionhosting\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-22T14:59:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-17T02:27:02+00:00\" \/>\n<meta name=\"author\" content=\"Christopher Maiorana\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:site\" content=\"@InMotionHosting\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Christopher Maiorana\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/\"},\"author\":{\"name\":\"Christopher Maiorana\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f\"},\"headline\":\"Add Custom Post Type to Your Theme Functions File\",\"datePublished\":\"2018-06-22T14:59:46+00:00\",\"dateModified\":\"2021-08-17T02:27:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/\"},\"wordCount\":573,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"articleSection\":[\"WordPress Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/\",\"name\":\"Add Custom Post Type to Your Theme Functions File | InMotion Hosting\",\"isPartOf\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\"},\"datePublished\":\"2018-06-22T14:59:46+00:00\",\"dateModified\":\"2021-08-17T02:27:02+00:00\",\"description\":\"In this article, we're going to continue with custom post types and show you how to bring them into your theme.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.inmotionhosting.com\/support\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Add Custom Post Type to Your Theme Functions File\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#website\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"name\":\"InMotion Hosting Support Center\",\"description\":\"Web Hosting Support &amp; Tutorials\",\"publisher\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#organization\",\"name\":\"InMotion Hosting\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"contentUrl\":\"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg\",\"width\":696,\"height\":696,\"caption\":\"InMotion Hosting\"},\"image\":{\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/inmotionhosting\/\",\"https:\/\/x.com\/InMotionHosting\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f\",\"name\":\"Christopher Maiorana\",\"description\":\"Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/chris-m-4623144b\/\"],\"url\":\"https:\/\/www.inmotionhosting.com\/support\/author\/christopherm\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Add Custom Post Type to Your Theme Functions File | InMotion Hosting","description":"In this article, we're going to continue with custom post types and show you how to bring them into your theme.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/","og_locale":"en_US","og_type":"article","og_title":"Add Custom Post Type to Your Theme Functions File | InMotion Hosting","og_description":"In this article, we're going to continue with custom post types and show you how to bring them into your theme.","og_url":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/","og_site_name":"InMotion Hosting Support Center","article_publisher":"https:\/\/www.facebook.com\/inmotionhosting\/","article_published_time":"2018-06-22T14:59:46+00:00","article_modified_time":"2021-08-17T02:27:02+00:00","author":"Christopher Maiorana","twitter_card":"summary_large_image","twitter_creator":"@InMotionHosting","twitter_site":"@InMotionHosting","twitter_misc":{"Written by":"Christopher Maiorana","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/#article","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/"},"author":{"name":"Christopher Maiorana","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f"},"headline":"Add Custom Post Type to Your Theme Functions File","datePublished":"2018-06-22T14:59:46+00:00","dateModified":"2021-08-17T02:27:02+00:00","mainEntityOfPage":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/"},"wordCount":573,"commentCount":0,"publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"articleSection":["WordPress Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/","url":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/","name":"Add Custom Post Type to Your Theme Functions File | InMotion Hosting","isPartOf":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#website"},"datePublished":"2018-06-22T14:59:46+00:00","dateModified":"2021-08-17T02:27:02+00:00","description":"In this article, we're going to continue with custom post types and show you how to bring them into your theme.","breadcrumb":{"@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.inmotionhosting.com\/support\/edu\/wordpress\/add-custom-post-type-to-your-theme-functions-file\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.inmotionhosting.com\/support\/"},{"@type":"ListItem","position":2,"name":"Add Custom Post Type to Your Theme Functions File"}]},{"@type":"WebSite","@id":"https:\/\/www.inmotionhosting.com\/support\/#website","url":"https:\/\/www.inmotionhosting.com\/support\/","name":"InMotion Hosting Support Center","description":"Web Hosting Support &amp; Tutorials","publisher":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.inmotionhosting.com\/support\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.inmotionhosting.com\/support\/#organization","name":"InMotion Hosting","url":"https:\/\/www.inmotionhosting.com\/support\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/","url":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","contentUrl":"https:\/\/www.inmotionhosting.com\/support\/wp-content\/uploads\/2023\/02\/inmotion-hosting-logo-yoast.jpg","width":696,"height":696,"caption":"InMotion Hosting"},"image":{"@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/inmotionhosting\/","https:\/\/x.com\/InMotionHosting"]},{"@type":"Person","@id":"https:\/\/www.inmotionhosting.com\/support\/#\/schema\/person\/c6922c56c84e17079fd558e07b7ef72f","name":"Christopher Maiorana","description":"Christopher Maiorana joined the InMotion community team in 2015 and regularly dispenses tips and tricks in the Support Center, Community Q&A, and the InMotion Hosting Blog.","sameAs":["https:\/\/www.linkedin.com\/in\/chris-m-4623144b\/"],"url":"https:\/\/www.inmotionhosting.com\/support\/author\/christopherm\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"primary_category":null,"_links":{"self":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/4552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/comments?post=4552"}],"version-history":[{"count":1,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/4552\/revisions"}],"predecessor-version":[{"id":83676,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/posts\/4552\/revisions\/83676"}],"wp:attachment":[{"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/media?parent=4552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/categories?post=4552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inmotionhosting.com\/support\/wp-json\/wp\/v2\/tags?post=4552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}