Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save quangmai911/52c5f96ede742bd201bdbf8433bd88c1 to your computer and use it in GitHub Desktop.
Save quangmai911/52c5f96ede742bd201bdbf8433bd88c1 to your computer and use it in GitHub Desktop.
CPT Docs
// Function to add Custom Post Type.
function olympus_custom_post_type()
{
// Register the doc post type
register_post_type( 'docs', array(
'labels' => array(
'name' => esc_html__( 'Documentation', 'olympus' ),
'singular_name' => esc_html__( 'Document', 'olympus' ),
'add_new' => esc_html__( 'Add New', 'olympus' ),
'add_new_item' => esc_html__( 'Add New Document', 'olympus' ),
'edit_item' => esc_html__( 'Edit Document', 'olympus' ),
'new_item' => esc_html__( 'Add New Document', 'olympus' ),
'view_item' => esc_html__( 'View Document', 'olympus' ),
'search_items' => esc_html__( 'Search Document', 'olympus' ),
'not_found' => esc_html__( 'No Documents Found', 'olympus' ),
'not_found_in_trash' => esc_html__( 'No Documents Found In Trash', 'olympus' ),
'menu_name' => esc_html__( 'Documentation', 'olympus' ),
),
'public' => true,
'show_ui' => true,
'can_export' => true,
'show_in_rest' => true,
'capability_type' => 'page',
'rewrite' => array( 'slug' => 'documentation' ),
'supports' => array( 'title', 'editor' ),
) );
// Register the doc taxonomy
register_taxonomy( 'doc_categories', array('docs'), array(
'hierarchical' => true,
'labels' => array(
'name' => _x( 'Categories', 'taxonomy general name', 'olympus' ),
'singular_name' => _x( 'Category', 'taxonomy singular name', 'olympus' ),
'search_items' => __( 'Search Categories', 'olympus' ),
'all_items' => __( 'All Categories', 'olympus' ),
'parent_item' => __( 'Parent Category', 'olympus' ),
'parent_item_colon' => __( 'Parent Category:', 'olympus' ),
'edit_item' => __( 'Edit Category', 'olympus' ),
'update_item' => __( 'Update Category', 'olympus' ),
'add_new_item' => __( 'Add New Category', 'olympus' ),
'new_item_name' => __( 'New Category Name', 'olympus' ),
'menu_name' => __( 'Categories', 'olympus' ),
),
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'doc-category' ),
) );
}
add_action( 'init', 'olympus_custom_post_type' );
@quangmai911
Copy link
Author

As some of you opt by installing plugins as BetterDocs, for instance, to then add your Docs and connect to Fluent Support, and others prefer to have a code that can be added to the Child Theme's functions.php but does not know how, I am taking the liberty of sharing with you my Custom Post Type (CPT) so that you can use.
It supports Category as well as Taxonomy, and Gutenberg.
Just in case you use the Classic Editor, please edit the code and remove the following line of code:
'show_in_rest' => true,

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