Skip to content

Instantly share code, notes, and snippets.

@galengidman
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galengidman/526f4d32bd0bd38ccc89 to your computer and use it in GitHub Desktop.
Save galengidman/526f4d32bd0bd38ccc89 to your computer and use it in GitHub Desktop.
WordPress post type and taxonomy setup for a knowledge base.
<?php
add_action( 'init', 'kb_register_post_types' );
function kb_register_post_types() {
register_post_type( 'kb_article', array(
'labels' => array(
'name' => 'Articles',
'singular_name' => 'Article',
'menu_name' => 'Knowledge Base',
'name_admin_bar' => 'KB Article',
'all_items' => 'Articles',
'add_new_item' => 'Add New Article',
'edit_item' => 'Edit Article',
'new_item' => 'New Article',
'view_item' => 'View Article',
'search_items' => 'Search Articles',
'not_found' => 'No articles found.',
'not_found_in_trash' => 'No articles found in trash.'
),
'public' => true,
'menu_icon' => 'dashicons-sos',
'rewrite' => array(
'slug' => 'kb',
'with_front' => false
),
'has_archive' => true,
'supports' => array(
'title',
'editor',
'revisions'
),
) );
}
add_action( 'init', 'kb_register_taxonomies' );
function kb_register_taxonomies() {
register_taxonomy( 'kb_category', 'kb_article', array(
'hierarchical' => true,
'rewrite' => array(
'slug' => 'category',
'with_front' => false,
)
) );
}

Paste the above code into your functions.php file. You may find the Custom Post Type Permalinks plugin useful for customizing permalinks on a per-post-type basis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment