25% off ProSNIPC25OFF

Register a Services Post Type

Registers a Services custom post type with an archive, excerpt, and thumbnail support for service listing pages.

PHPby SnipCraft
php
<?php
add_action( 'init', 'scseed_register_services_cpt' );
if ( ! function_exists( 'scseed_register_services_cpt' ) ) {
    function scseed_register_services_cpt() {
        $labels = array(
            'name'               => 'Services',
            'singular_name'      => 'Service',
            'add_new_item'       => 'Add New Service',
            'edit_item'          => 'Edit Service',
            'new_item'           => 'New Service',
            'view_item'          => 'View Service',
            'search_items'       => 'Search Services',
            'not_found'          => 'No services found',
            'not_found_in_trash' => 'No services found in trash',
            'menu_name'          => 'Services',
        );
        register_post_type( 'service', array(
            'labels'       => $labels,
            'public'       => true,
            'has_archive'  => true,
            'rewrite'      => array( 'slug' => 'services' ),
            'supports'     => array( 'title', 'editor', 'thumbnail', 'excerpt', 'page-attributes' ),
            'show_in_rest' => true,
            'menu_icon'    => 'dashicons-admin-tools',
        ) );
    }
}
#content#cpt#register-post-type#services