Create a custom post type called “Books” in WordPress to use in functions.php

|

Here is an example of how you can create a custom post type called “Books” in WordPress using the register_post_type function in your theme’s functions.php file:

function create_book_post_type() {
  register_post_type( 'book',
    array(
      'labels' => array(
        'name' => __( 'Books' ),
        'singular_name' => __( 'Book' )
      ),
      'public' => true,
      'has_archive' => true,
      'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    )
  );
}
add_action( 'init', 'create_book_post_type' );

This code creates a new post type called “Books” and adds it to the WordPress admin interface. The labels array sets the labels for the post type in the WordPress admin, the ‘public’ parameter set to true makes the post type visible to the public, the ‘has_archive’ parameter set to true makes an archive page of the post type available, the supports parameter enables the title, editor, author, thumbnail, excerpt and comments for this custom post type.

You can also customize the post type by adding more parameters such as ‘rewrite’ or ‘taxonomies’ to the array, you can find more information on the available parameters in the WordPress documentation here: https://codex.wordpress.org/Function_Reference/register_post_type

And then use the add_action function to add the create_book_post_type function to the init action so that it runs when the theme is initialized.

Please note that this is just an example and you may need to adjust the code to fit your specific requirements.

Similar Posts