Created
February 9, 2025 10:16
-
-
Save mommaroodles/bc7b2c30311882b5e45af02b1c4db8f5 to your computer and use it in GitHub Desktop.
Register Custom Post Type Books
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Register a custom post type called "Books". | |
*/ | |
function custom_post_type_books() { | |
$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' => __( 'Add New Book', 'textdomain' ), | |
'new_item' => __( 'New Book', 'textdomain' ), | |
'edit_item' => __( 'Edit Book', 'textdomain' ), | |
'view_item' => __( 'View Book', 'textdomain' ), | |
'all_items' => __( 'All Books', 'textdomain' ), | |
'search_items' => __( 'Search Books', 'textdomain' ), | |
'parent_item_colon' => __( 'Parent Books:', 'textdomain' ), | |
'not_found' => __( 'No books found.', 'textdomain' ), | |
'not_found_in_trash' => __( 'No books found in Trash.', 'textdomain' ) | |
); | |
$args = array( | |
'labels' => $labels, | |
'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, | |
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ) | |
); | |
register_post_type( 'book', $args ); | |
} | |
add_action( 'init', 'custom_post_type_books' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment