Ben Fairbanks

Freelance Website Developer

Custom Posts in WordPress

Apr 9, 2017

Creating a custom post in word press is pretty easy. Once you've created the custom post type just go into the admin section and click the create new button. With that dad joke out of the way creating a custom post class is no difficult feat either.

Probably the easiest way to create a custom post type is by simply adding a plugin to your WordPress site. This option works, but there are downsides to that, namely the need for a plugin that you do not control, i.e. can be taken off the market, stop updating, or any other variety of terrible things. So to avoid that it is best to build your own custom classes.

The first step to this is to download WordPress. This may seem like something that should not even be mentioned, but WordPress sites can also be created through an online portal. This denies us the opertunity to muddle around in the files, as we will need to to create a custom class. Downloading WordPress requires very little in terms of effort, and creating a custom wordpress theme is not hard either. Creating a custom theme is neccisary because the templates that come pre-installed on WordPress are loaded with functions and files that we may not want. Thus creating a new theme.

With the set up out of the way we can get to the crux of this tutorial. Head on over to the custom theme folder you just created. Open up functions.php in your prefered text editor. Copy and enter the text in the gist below.

Rename the function and the post type names and hit save. A new custom post class given the name and the paramaters that you have set will appear in the admin dashboard of your wordpress project. There are many different labels that you can add to your custom post. The custom post will iteract with the rest of WordPress in much the same way as any other inharent part of the program, so using it alongside plugins is not a problem. You should now be ready to charge headfirst into the brave world of custom post types. </p>

Share this on Twitter!