This tutorial will go over the code needed to create a WordPress custom post type for a portfolio section. After you complete this tutorial, you will have a Portfolio tab in your WordPress Dashboard that will allow you to create new portfolio items.
- Go to Github and download the WP Custom Post Type class here.
- Create a new directory in the
- Copy the
CPT.phpfile from the download into the
- Open the
functions.phpfile and at the bottom add the following code:functions.phpPHP1234/*** Custom Post Types*/require get_template_directory() . '/inc/post-types/CPT.php';
- Create a new file in the
register-portfolio.phpwith the following code:register-portfolio.phpPHP12345678910111213141516171819<?php$portfolio = new CPT(array('post_type_name' => 'portfolio','singular' => __('Portfolio', 'bootstrapwp'),'plural' => __('Portfolio', 'bootstrapwp'),'slug' => 'portfolio'),array('supports' => array('title', 'editor', 'thumbnail', 'comments'),'menu_icon' => 'dashicons-portfolio'));$portfolio->register_taxonomy(array('taxonomy_name' => 'portfolio_tags','singular' => __('Portfolio Tag', 'bootstrapwp'),'plural' => __('Portfolio Tags', 'bootstrapwp'),'slug' => 'portfolio-tag'));
- Open the
functions.phpfile and add the following code to the bottom:functions.phpPHP12//Portfolio Custom Post Typerequire get_template_directory() . '/inc/post-types/register-portfolio.php';
Note: As always the video goes in more detail about each step in this tutorial.
Notes from the Video
You can download the WP Custom Post Type class here.
Here is a link to the WordPress codex that goes over all the different parameters you can use when creating a custom post type.
The different Dashicons that can be used can be found here.
Please let me know what you think of this tutorial and if you need help with anything.