That Stubborn WordPress Custom Post Type

The WordPress Custom Post Type. CPT for short. Nothing amazing about it. Many themes include them. Often they are Portfolio, FAQ, Events, or other specifically created posts.

What do we need to do to add a Custom Post Type to a theme without these baked in already?

It is a two step process that requires a proper Child Theme and some code as shown below:

We start by properly using init in the Child Theme’s functions.php

add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'members',
 'labels' => array(
 'name' => __( 'Members' ),
 'singular_name' => __( 'Member' )
 'public' => true,
 'has_archive' => true,
 'show_ui' => true,
 'show_in_nav_menus' => true,
 'menu_position' => 5,
 'rewrite' => array(
 'slug' => 'members',
 'with_front' => FALSE,
 'supports' => array(
 'taxonomies' => array('post_tag'),
 'update_count_callback' => '_update_post_term_count'

What does that do? It creates a Custom Post Type which includes a taxonomy of Tags. Yes, you can also include the taxonomy Category by using this instead:

'taxonomies' => array('category','post_tag')

Next, we need to be able to link to these Custom Post Post Types:

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
 if(is_category() || is_tag()) {
 $post_type = get_query_var('post_type');
 $post_type = $post_type;
 $post_type = array('nav_menu_item','post','members');
 return $query;

Note, above is a specific and basic example. We can further customize with an archive-members.php Page Template.  Much, much more can be done with CPT’s!