I recently released a plugin on WordPress.org that registers a portfolio post type, related taxonomies, and adds an image when you’re viewing the items in the dashboard.

I’ve held onto to the plugin for a while in GitHub since it’s an easy thing for any developer to build out- but I’ve recently been thinking that a standard plugin in the repository might be beneficial as it could make more themes more portable. (Especially for users of my Portfolio Press theme)
And since I expect people to modify this a bit as well, I wanted walk through of the code.
Plugin Header
<?php
/*
Plugin Name: Portfolio Post Type Gist
Plugin URI: https://wptheming.com
Description: Enables a portfolio post type and taxonomies.
Version: 0.1
Author: Devin Price
Author URI: https://wptheming.com/portfolio-post-type/
License: GPLv2
*/
Explanation: All plugins need to have basic header data in order to show up in plugin admin page. If you don’t want to get updates to the plugin (I don’t expect many), change the name to something different. Shoot, feel free to change any of this- that’s why it’s being released!
Enable the Portfolio Post Type
function portfolioposttype() {
/**
* Enable the Portfolio custom post type
* http://codex.wordpress.org/Function_Reference/register_post_type
*/
$labels = array(
'name' => __( 'Portfolio', 'portfolioposttype' ),
'singular_name' => __( 'Portfolio Item', 'portfolioposttype' ),
'add_new' => __( 'Add New Item', 'portfolioposttype' ),
'add_new_item' => __( 'Add New Portfolio Item', 'portfolioposttype' ),
'edit_item' => __( 'Edit Portfolio Item', 'portfolioposttype' ),
'new_item' => __( 'Add New Portfolio Item', 'portfolioposttype' ),
'view_item' => __( 'View Item', 'portfolioposttype' ),
'search_items' => __( 'Search Portfolio', 'portfolioposttype' ),
'not_found' => __( 'No portfolio items found', 'portfolioposttype' ),
'not_found_in_trash' => __( 'No portfolio items found in trash', 'portfolioposttype' )
);
$args = array(
'labels' => $labels,
'public' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ),
'capability_type' => 'post',
'rewrite' => array( 'slug' => 'portfolio' ), // Permalinks format
'menu_position' => 5,
'has_archive' => true,
'menu_icon' => 'dashicons-portfolio',
);
register_post_type( 'portfolio', $args );
}
add_action( 'init', 'portfolioposttype' );
This is the basic code needed to register the portfolio post type. I’ve wrapped it all in one function that fires on init. For a deeper explanation of all the arguments ($args) check out the codex post.
Register Taxonomies
Wrapped in that same function I also register two taxonomies for categories and tags. Since that code is long, and basically just a bunch of labels I’ll point you to the actual code on GitHub. If you don’t want taxonomies, you don’t actually need that code.
Use Post Thumbnails
If you want your post type to be able to use thumbnails, you’ll need to register it:
// Allow thumbnails to be used on portfolio post type
add_theme_support( 'post-thumbnails', array( 'portfolio' ) );
View Thumbnail Images in Column View of Dashboard
For something like portfolio items, it’s nice to see the images when you’re scanning posts in the dashboard. I wrote about how that functionality works in a separate post.
Display a Custom Icon for Portfolio Menus
I was lucky enough to get Ben Dunkle (the designer of the WordPress icons), to make some portfolio icons for me for the first version of this plugin. Now, most plugins use dashicons for custom post types.
Custom Meta Boxes
This plugin doesn’t register any custom meta boxes, but those obviously might be useful if you want to include a link a website, or a purchase button, etc. If you’re interested in doing that- see my post on adding custom meta boxes to post types.