August 2017
Beginner
412 pages
10h 30m
English
To register a new post type, all you have to do is add some simple code to your theme's functions.php file. It's good practice to tie the creation of the new type to the init function of the theme so that it gets called at the right moment in the booting process. The initial, blank, custom post type code looks like this:
function book_init() {
register_post_type('book');
}
add_action('init', 'book_init');
The register_post_type() function takes an array as its second parameter, and in that array, you can specify whether the object is public or should be involved in rewriting the URL, what elements it supports on its editing page, and so on. Let's set up an array of all the arguments and then pass it to the function. ...
Read now
Unlock full access