Home Wordpress How to create custom post type to a WordPress?

How to create custom post type to a WordPress?

Author

Date

Category

To add a custom post type to a WordPress site, you would use the register_post_type() function. For example, to create a custom post type called “Books,” you would add the following code to your functions.php file:

function custom_post_type() {
  $args = array(
    'public' => true,
    'label'  => 'Books'
  );
  register_post_type( 'books', $args );
}
add_action( 'init', 'custom_post_type' );
PHP

This code creates a custom post type called “Books” and adds it to the WordPress site. You can then use this custom post type to add and display books on your site.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Subhash Shipu

PHP Expert

Hey there! I'm a PHP geek on a mission to blog my way through the coding chaos. When I'm not chasing semicolons, I'm busy cuddling my pet Coco, who thinks debugging means chasing her own tail. Join the fun!

Subscribe

Recent posts