Your cart is currently empty!
Register custom post types
Registers a custom post type with a category. Must be set to run everywhere.
add_action( 'init', function() {
// Post Type
$args = [
'labels' => [ 'name' => 'Custom Items', 'singular_name' => 'Custom Item' ],
'menu_icon' => 'dashicons-admin-site',
'supports' => [ 'title', 'editor', 'thumbnail' ],
'rewrite' => [ 'slug' => 'custom_item' ],
'has_archive' => true,
'show_in_menu' => true,
'show_ui' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'hierarchical' => false,
'can_export' => true,
'show_in_nav_menus' => true,
'query_var' => true,
'show_in_rest' => false,
'public' => true,
'capability_type' => 'post',
];
register_post_type( 'custom_item', $args );
// Post Type Category
$args = [
'labels' => [ 'name' => 'Custom Categories', 'singular_name' => 'Custom Category' ],
'hierarchical' => true,
'rewrite' => [ 'slug' => 'custom_category' ],
'show_ui' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'show_admin_column' => false,
'query_var' => true,
'show_in_rest' => false,
];
register_taxonomy( 'custom_category', [ 'custom_item' ], $args );
} );
Instructions for Register custom post types
- Log into a staging or locally hosted clone of your site.
- Install and activate Code Snippets plugin.
- WP Admin > Snippets > Add New
- Copy and paste the code from the section above.
- Check to ensure formatting came over properly.
- Customize the code as desired.
- Add a meaningful title.
- Select whether to run on front-end or back-end (or both).
- Click “Save and Activate”.
- Test your site to ensure it works.
- Disable if any problems, or recover.
- Repeat for live environment.
Need help modifying Register custom post types?
Contact me. I can help with fitting projects or refer to my partner.
License
All code snippets are licensed GPLv2 (or later) matching WordPress licensing.
Except when otherwise stated in writing the copyright holders and/or other parties provide the program as-is without warranty of any kind, either expressed or implied, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose.
Disclaimer of warranty