We can create our own custom post types.
We can call them whatever we want.
They are content types like posts and pages.
We create a custom post type for adding different feature to our website.
We can add category to our post.
For creating a custom post type we have to add function in function.php.
// Our custom post type function
function create_post_type() {
register_post_type( 'movies',
// CPT Options
array(
'labels' => array(
'name' => _( 'Movies' ),
'singular_name' => _( 'Movie' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'movies'),
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_post_type' );
this code registers a post type 'movies' with an array of arguments.
These arguments are the options of our custom post type.
This array has two parts, the first part is labels, which itself is an array.
The second part contains other arguments like public visibility, has archive, and slug that will be used in URLs for this post type.
0 Comment(s)