AI Verified

Name

Add a custom post type to WordPress named "Slides"

About

Add a custom post type to WordPress without having to use a plugin.

Language

PHP

Rating

Voted: 1 by 1 user(s)

How to Setup Snippet

Just add it to Code Snippets. It's always good to re-save permalinks in WordPress settings after doing this to make sure the permalink is registered properly.

Codevault

Grassmediaweb

Scroll down to see more snippets from this codevault.

Wordpress Compatability

The author has indicated that this snippet is compatable up to wordpress version: 6.1

Our AI bot has checked this snippet is compatable up to wordpress version: 6.1

Code Snippet Plugin Sync

Free & Pro

Download this snippet by clicking the download button, then head over to the Code Snippet Plugin settings in your wordpress admin dashboard, select the import menu then upload this file to import into your wordpress site.

Pro Only (Coming Soon)

You will be able to click a button and sync this snippet to your wordpress site automatically and from your dashboard manage all code snippets across all your wordpress sites that have the Code Snippets Pro plugin installed.

History

Last modified:

22/11/2023

Important Note

This snippet has the following status:

AI Verified

This snippet has been tested by our AI bot, see any comments below.

AI Bot Comments:

Found 0 vulnerabilities

Add a custom post type to WordPress named "Slides"

 
                    
1// Register Custom Post Type
2function custom_post_type_slides() {
3 
4 $labels = array(
5 'name' => _x( 'Slides', 'Post Type General Name', 'text_domain' ),
6 'singular_name' => _x( 'Slide', 'Post Type Singular Name', 'text_domain' ),
7 'menu_name' => __( 'Slides', 'text_domain' ),
8 'name_admin_bar' => __( 'Slides', 'text_domain' ),
9 'archives' => __( 'Slide Archives', 'text_domain' ),
10 'attributes' => __( 'Slide Attributes', 'text_domain' ),
11 'parent_item_colon' => __( 'Parent Slide:', 'text_domain' ),
12 'all_items' => __( 'All Slides', 'text_domain' ),
13 'add_new_item' => __( 'Add New Slide', 'text_domain' ),
14 'add_new' => __( 'Add New', 'text_domain' ),
15 'new_item' => __( 'New Slide', 'text_domain' ),
16 'edit_item' => __( 'Edit Slide', 'text_domain' ),
17 'update_item' => __( 'Update Slide', 'text_domain' ),
18 'view_item' => __( 'View Slide', 'text_domain' ),
19 'view_items' => __( 'View Slides', 'text_domain' ),
20 'search_items' => __( 'Search Slide', 'text_domain' ),
21 'not_found' => __( 'Slide Not found', 'text_domain' ),
22 'not_found_in_trash' => __( 'Slide Not found in Trash', 'text_domain' ),
23 'featured_image' => __( 'Featured Image', 'text_domain' ),
24 'set_featured_image' => __( 'Set featured image', 'text_domain' ),
25 'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
26 'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
27 'insert_into_item' => __( 'Insert into Slide', 'text_domain' ),
28 'uploaded_to_this_item' => __( 'Uploaded to this Slide', 'text_domain' ),
29 'items_list' => __( 'Slides list', 'text_domain' ),
30 'items_list_navigation' => __( 'Slides list navigation', 'text_domain' ),
31 'filter_items_list' => __( 'Filter Slides list', 'text_domain' ),
32 );
33 $args = array(
34 'label' => __( 'Slide', 'text_domain' ),
35 'description' => __( 'Custom Slides', 'text_domain' ),
36 'labels' => $labels,
37 'supports' => array( 'title', 'editor', 'thumbnail' ), // Add 'thumbnail' for featured image capability
38 'hierarchical' => false,
39 'public' => true,
40 'show_ui' => true,
41 'show_in_menu' => true,
42 'menu_position' => 5,
43 'show_in_admin_bar' => true,
44 'show_in_nav_menus' => true,
45 'can_export' => true,
46 'has_archive' => true,
47 'exclude_from_search' => false,
48 'publicly_queryable' => true,
49 'capability_type' => 'post',
50 );
51 register_post_type( 'slides', $args );
52 
53}
54add_action( 'init', 'custom_post_type_slides', 0 );

1

Related Snippets

Please see some snippets below related to this snippet..

WordPress Admin

AI Verified

2

Disable admin notices by text string

Added: 1 year ago

Last Updated: 1 year ago

In $forbidden_message_strings array, provide a list of keywords or phrases that you want to disable. Provide a longer phrase to increase specificity

WordPress Admin

AI Verified

0

Regenerate thumbnails - no extra plugin required.

Added: 1 year ago

Last Updated: 1 year ago

WordPress Admin

AI Verified

1

View update info on posts

Added: 1 month ago

Last Updated: 1 month ago

Other Snippets in this Codevault

These are some popular snippets from this users codevault..

WordPress Admin

AI Verified

3

Redirect after successful non-admin login

Added: 1 year ago

Last Updated: 4 months ago

This snippet redirects a non-admin user to the URL or page/post of choice.

WordPress Admin

AI Verified

1

Add a custom post type to WordPress named "Slides"

Added: 11 months ago

Last Updated: 7 months ago

Add a custom post type to WordPress without having to use a plugin.

WordPress Admin

AI Verified

1

Add custom fields to user profile

Added: 1 year ago

Last Updated: 1 year ago

This is a simple and very flexible code snippet for adding custom fields to a user profile. Saves a bulky extra plugin!