PHP HTML CSS JS
Click to copy

Paste to your child theme's functions.php file

/**
 * Register custom post types
 *
 * @since 1.0
 */

function my_custom_post_types() {
	register_post_type( 'portfolio', array(
		'public'        => true,
		'menu_position' => 20,
		'taxonomies'    => array( 'portfolio_category' ),
		'has_archive'   => false,
		'supports'      => array( 'title', 'editor', 'thumbnail' ),
		'labels'        => array(
			'name'               => 'Portfolio',
			'singular_name'      => 'Portfolio',
			'menu_name'          => 'Portfolio',
			'name_admin_bar'     => 'Portfolio',
			'add_new_item'       => 'Add New Portfolio Item',
			'edit_item'          => 'Edit Portfolio Item',
			'new_item'           => 'New Portfolio Item',
			'view_item'          => 'View Portfolio Item',
			'search_items'       => 'Search Portfolio',
			'not_found'          => 'Nothing found',
			'not_found_in_trash' => 'Nothing found in trash',
			'all_items'          => 'View All'
		)
	) );
}
add_action( 'init', 'my_custom_post_types', 1 );

/**
 * Create taxonomies to associate with post type.
 *
 * @since 1.0
 */

function my_custom_taxonomies() {
	register_taxonomy( 'portfolio_category', 'portfolio', array(
		'hierarchical' => true,
		'show_ui'      => true,
		'query_var'    => true,
		'rewrite'      => array(
			'slug'         => 'portfolio/category',
			'with_front'   => false,
			'hierarchical' => true
		),
		'capabilities' => array( 'manage_categories' )
	) );
}
add_action( 'init', 'my_custom_taxonomies', 0 );
Click to copy
Click to copy
Click to copy

How to Add Custom Post Type and Taxonomies to WordPress

How to create a custom post type that can be used as a portfolio. You can also add custom categories to your new post types.

Labs

Get the latest MD sent straight to your inbox

There's always something new in the works in the MD Labs! Join the email list to get the newest content and releases sent straight to your inbox.*

Join the MD Newsletter

* I only email you when there's something new, or to share an exciting MD sneak peak.