Skip to content

Instantly share code, notes, and snippets.

@szbl
Created July 24, 2015 18:12
Show Gist options
  • Save szbl/8bf0c27c860079100976 to your computer and use it in GitHub Desktop.
Save szbl/8bf0c27c860079100976 to your computer and use it in GitHub Desktop.
<?php
/*
Reference: https://codex.wordpress.org/Function_Reference/register_post_type
*/
// hook into the "init" action
add_action( 'init', 'sam_register_post_types' );
function sam_register_post_types()
{
register_post_type(
'sam-books',
array(
'labels' => array(
'name' => 'Books',
'singular_name' => 'Book',
'menu_name' => 'My Books',
'name_admin_bar' => 'Book',
'all_items' => 'All Books',
'add_new' => 'Add New',
'add_new_item' => 'Add New Book',
'new_item' => 'New Book',
'edit_item' => 'Edit Book',
'view_item' => 'View Book',
'search_items' => 'Search Books',
'not_found' => 'No books found',
'not_found_in_trash' => 'No books found in trash',
),
'description' => 'Books in Sam\'s library.',
// public to the world?
'public' => true,
// hide from public search?
'exclude_from_search' => false,
// Can it be seen in standard front-end requests/queroes?
'publicly_queryable' => true,
// show the UI in the admin?
'show_ui' => true,
// show the menu item in the admin?
'show_in_menu' => true,
// Can this be used with nav menus?
'show_in_nav_menus' => true,
// Should we show in the admin tool bar for creating new items?
'show_in_admin_bar' => true,
// where to show in menu, see:
// https://codex.wordpress.org/Function_Reference/register_post_type#menu_position
'menu_position' => 15,
// image or dashicons slug ()
'menu_icon' => 'dashicons-book',
// Can this post have children?
'hierarchical' => false,
// What features does this post support?
'supports' => array(
// post title
'title',
// WYSIWYG
'editor',
// author managemnet (drop-down in meta box)
'author',
// featured image support
'thumbnail',
'excerpt',
'trackbacks',
// post meta
'custom-fields',
'revisions',
// Menu Order and Parent Post options
'page-attributes',
'post-formats'
),
// should this post have an archive page?
// e.g. http://mysite.com/my-books/ would be an archive listing page.
'has_archive' => false,
'rewrite' => array(
// use the blog permalink prefix if it ecists?
'with_front' => false,
// custom URL slug, otherwise it defaults to "sam-books"
'slug' => 'my-books'
// support for permlaink RSS feed?g
'feeds' => true,
// should it support /page/2/ etc. functionality?
'pages' => true
)
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment