Creating a Custom Post Type (CPT) in Astratic theme

WordPress has started as a simple blogging platform but treating it the same way now would be a big understatement. It is a robust Content Management System (CMS) that goes far beyond posts and articles. One way to discover its full potential is by using a custom post type.

What is a custom post type?

Let’s imagine that you want to start a platform with high school reviews. You want to collect facilities from the neighborhood providing some useful data like:

To create such kind of library you can use CPT. It enables the ability to build a template for any kind of post and makes possible ordering them in new taxonomy (e.g. by districts or cities in the region). Interested? Let’s dive in!

How to create a CPT?

Let’s assume that we want to publish school review on the website using Custom Post Type (CPT). We start by finding the functions.php file in the directory with the Astratic template. Finally, paste the code, remembering to replace the labels and other arguments according to your needs.

function job_post_type() {
    $labels = array(
        'name'                => 'School review',
        'singular_name'       => 'School review',
        'menu_name'           => 'School review',
        'parent_item_colon'   => 'School review',
        'all_items'           => 'All schools',
        'view_item'           => 'See review',
        'add_new_item'        => 'Add school review',
        'add_new'             => 'Add new school',
        'edit_item'           => 'Edit school',
        'update_item'         => 'Update',
        'search_items'        => 'Search reviews',
        'not_found'           => 'Not found',
        'not_found_in_trash'  => 'Not found'
    ); 
    $args = array(
        'label' => 'school',
        'rewrite' => array(
            'slug' => 'school-reviews'
        ),
        'description'         => 'School review',
        'labels'              => $labels,
        'supports'            => array( 'title', 'thumbnail'),
        'taxonomies'          => array(),
        'hierarchical'        => false,
        'public'              => true, 
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 4,
        'menu_icon'           => 'dashicons-id-alt',
        'can_export'          => true,
        'has_archive'         => false,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'capability_type'     => 'post',
    );
    register_post_type( 'school review', $args );
} 
add_action( 'init', 'job_post_type', 0 );

As you can see, register_post_type takes a lot of arguments. Fortunately, in most cases it is enough to change a few basic ones:

Send the file to the server, if everything went well, a new item will appear in the menu.

If you are interested in building own page templates read our article. We also send other useful tutorials from WPBeginner and Cloudways.

Do you have any questions? We are here to help! 🙂

Need help?

Thank you!

We will answer to your message as soon as possible

Need help? support-icon