Skip to content

Instantly share code, notes, and snippets.

@imvarunkmr
Last active April 2, 2017 05:41
Show Gist options
  • Save imvarunkmr/dce59e58968adaa6bef6a3e8be8389cb to your computer and use it in GitHub Desktop.
Save imvarunkmr/dce59e58968adaa6bef6a3e8be8389cb to your computer and use it in GitHub Desktop.
<?php
// Using init action hook to register post type on loading
add_action( 'init', 'slug_book_init');
/**
* Register a book post type
*/
function slug_book_init() {
$labels = array(
'name' => _x( 'Books', 'post type general name', 'textdomain' ),
'singular_name' => _x( 'Book', 'post type singular name', 'textdomain' ),
'menu_name' => _x( 'Books', 'admin menu', 'textdomain' ),
'name_admin_bar' => _x( 'Book', 'add new on admin bar', 'textdomain' ),
'add_new' => _x( 'Add New', 'book', 'textdomain' ),
'add_new_item' => _x( 'Add New Book', 'textdomain' ),
'new_item' => _x( 'New Book', 'textdomain' ),
'edit_item' => _x( 'Edit Book', 'textdomain' ),
'view_item' => _x( 'View Book', 'textdomain' ),
'all_items' => _x( 'All Books', 'textdomain' ),
'search_items' => _x( 'Search Books', 'textdomain' ),
'parent_item_colon' => _x( 'Parent Books', 'textdomain' ),
'not_found' => _x( 'No books found', 'textdomain' ),
'not_found_in_trash' => _x( 'No books found in trash', 'textdomain' ),
);
$args = array(
'labels' => $labels,
'description' => __( 'Description.', 'textdomain' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'book' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
//'menu_icon' => 'dashicons-format-gallery',
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),
);
register_post_type( 'book', $args );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment