InMotion Hosting Support Center

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't need a plugin to create custom post types, it just makes the process easier by adding a user interface.

Once you have the code, custom post types can be incorporated into your theme (whether you're using a custom theme or a child theme).In this article, we'll show you how you can custom post types created in the Custom Post Type UI plugin and add them to your theme.

A Few Simple Facts

In order to accomplish the goals in this article, we will cover a few simple facts:

  • Why this is important
  • Where the code goes
  • How to copy code from the CPT UI plugin
  • How to copy the code to your functions.php file

That's all we'll need to do!

Why Is This Important?

In essence, this article will explain how you can take code created by a plugin and incorporate it into your theme so you don't need the plugin. There are many reasons why you might want to do this:

  • More control over your code
  • Fewer plugins to manage
  • Reduced complexity

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.

But, in the case of this article, we're working with a plugin that only creates and edits custom post types, which we can easily bring into a theme. Once you've created all the custom post types you require, there's no need to keep the plugin installed on your site.

Where Does the Code Go?

In this article, we'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 functions.php. This is a special file WordPress uses to run custom PHP functions associated with your theme.

First, we will need to access raw PHP code produced by the Custom Post Type UI plugin.

How to Copy Code From Custom Post Type UI

Now we will extract the PHP code for our custom post type from the plugin.

  1. Log into your WordPress Dashboard
  2. Click Tools under CPT UI (left panel)
  3. Choose the Get Code tab at the top

Which code should you copy? If you created multiple custom post types, you will want to copy the code under All CPT UI Post Types. If you only require one custom post type, you will see it listed under its own section.

Copy the Code into the Functions File

Now, you will only need to open your functions.php file in your theme directory:

/wp-content/themes/custom-theme-name/functions.php

In most cases, it is considered safe to begin a PHP block without closing it:

<?php
// The Custom Post Type code pasted here
// ...

With the PHP code for your custom post type added to the functions.php file, make sure to save the file. Also, make sure to disable the Custom Post Type UI plugin to avoid duplicate custom post types.

Was this article helpful?

Related Questions

Here are a few questions related to this article that our customers have asked:
Ooops! It looks like there are no questions about this page.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Support Center Login

Our Login page has moved, Click the button below to be taken to the login page.

Post a Comment

Name:
Email Address:
Phone Number:
Comment:
Submit

Please note: Your name and comment will be displayed, but we will not show your email address.

0 Questions & Comments

Post a comment

Back to first comment | top

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!