Videos Post Type With Video Categories
Registers a "Videos" post type with its own categories, for video libraries and tutorials kept separate from blog posts.
Opens WPIDE on
Code
// Names used in labels and URLs: edit to suit.
$wpide_type = array(
'name' => 'video', // Internal name: lowercase, max 20 characters, never change it once you have content.
'singular' => 'Video',
'plural' => 'Videos',
'slug' => 'videos',
);
add_action( 'init', function () use ( $wpide_type ) {
$s = $wpide_type['singular'];
$p = $wpide_type['plural'];
register_post_type( $wpide_type['name'], array(
'labels' => array(
'name' => $p,
'singular_name' => $s,
'menu_name' => $p,
'add_new_item' => "Add New $s",
'edit_item' => "Edit $s",
'new_item' => "New $s",
'view_item' => "View $s",
'view_items' => "View $p",
'all_items' => "All $p",
'search_items' => "Search $p",
'not_found' => 'Nothing found.',
'not_found_in_trash' => 'Nothing found in Trash.',
'archives' => "$s Archives",
'attributes' => "$s Attributes",
'insert_into_item' => "Insert into $s",
'uploaded_to_this_item' => "Uploaded to this $s",
'item_published' => "$s published.",
'item_updated' => "$s updated.",
),
'public' => true,
'has_archive' => $wpide_type['slug'],
'rewrite' => array( 'slug' => $wpide_type['slug'], 'with_front' => false ),
'show_in_rest' => true,
'menu_icon' => 'dashicons-video-alt3',
'menu_position' => 33,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'comments' ),
) );
register_taxonomy( 'video_category', $wpide_type['name'], array(
'labels' => array(
'name' => 'Video Categories',
'singular_name' => 'Video Category',
'menu_name' => 'Video Categories',
'all_items' => 'All Video Categories',
'edit_item' => 'Edit Video Category',
'view_item' => 'View Video Category',
'update_item' => 'Update Video Category',
'add_new_item' => 'Add New Video Category',
'new_item_name' => 'New Video Category Name',
'search_items' => 'Search Video Categories',
'not_found' => 'No video categories found.',
'parent_item' => 'Parent Video Category',
),
'hierarchical' => true,
'public' => true,
'rewrite' => array( 'slug' => 'video-category', 'with_front' => false ),
'show_admin_column' => true,
'show_in_rest' => true,
) );
} );
Notes
Visit Settings > Permalinks once after activating so the new URLs work.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.