How to Setup Custom Post Types in WordPress

How to Setup Custom Post Types in WordPress

Custom Post Types

WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp_posts database table, but are differentiated by a column called post_type

WordPress Post Types

In this tutorial I’m going to be showing you how to add Custom Post Types to your WordPress site.

We can use custom post types to separate post into dedicated sections on our site, separate from posts / pages.

In this instance we going to make a testimonial section on our WordPress site where we can house all the testimonials we get from clients.

custom post type

Step 1

Go to your themes functions.php file, To get there You can go via Appearance –> Editor and look for functions.php or theme functions or you can use a code editor and edit your themes function.php file directly via Wp-Content –> Themes –> Your Theme –> functions.php.

Before editing please take a backup of the file you are working on In case anything goes wrong.

Step 2

At the bottom of your functions.php add the following code to register the custom post type.

function my_custom_post_types() {
	$labels = array(
		'name'               => 'Testimonials',
		'singular_name'      => 'Testimonial',
		'menu_name'          => 'Testimonial',
		'name_admin_bar'     => 'Testimonial',
		'add_new'            => 'Add New',
		'add_new_item'       => 'Add New Testimonial',
		'new_item'           => 'New Testimonial',
		'edit_item'          => 'Edit Testimonial',
		'view_item'          => 'View Testimonial',
		'all_items'          => 'All Testimonials',
		'search_items'       => 'Search Testimonials',
		'parent_item_colon'  => 'Parent Testimonials:',
		'not_found'          => 'No testimonials found.',
		'not_found_in_trash' => 'No testimonials found in Trash.'

	$args = array(
		'labels'             => $labels,
        'description' 		 => 'Some testimonials from happy clients.',
		'public'             => true,
		'publicly_queryable' => true,
		'show_ui'            => true,
		'show_in_menu'       => true,
		'query_var'          => true,
		'rewrite'            => array( 'slug' => 'testimonials' ),
		'capability_type'    => 'post',
		'has_archive'        => true,
		'hierarchical'       => false,
                'menu_icon'          => 'dashicons-editor-quote',
		'menu_position'      => 60,
		'supports'           => array( 'title', 'editor', 'author', 'excerpt')

	register_post_type( 'testimonial', $args );
add_action( 'init', 'my_custom_post_types' );

The $labels Is an array of strings which are used in the custom post type learn more about Labels in WordPress

The $args are the arguments / options to go with the register_post_type function.

'labels'  => $labels, // our custom label array at the top
'description' => 'Some testimonials from happy clients.', // description of the post type
'public' => true, // Is it publicly viewable
'publicly_queryable' => true, // Is it publicly querayable, can someone search for it
'show_ui' => true, // Show in wordpress
'show_in_menu' => true, //Show in the menu (show the posts from the post type in the menu section)
'query_var' => true,
'rewrite' => array( 'slug' => 'testimonials' ), //Rewrite the slug address
'capability_type' => 'post', //Capabilities post / page
'has_archive' => true, //Has an Archive Page
'hierarchical' => false, //Allows Parent to be specified
'menu_position' => 60,
'supports' => array( 'title', 'editor', 'author', 'excerpt') //What can you post type support learn more about supports

Step 3

Done, click save and refresh your wordpress site and you should have a custom post type in the dashboard section on the left-hand side. And if you go to You’ll be greeted with the archive page for your custom post type.

Custom Post Type


If you wanted a different design for your archive page for specific posts typePost from your cut from your post type is displayed or designed you can add additional files to your themeAs follows:

For a single post-it would be single-{posttype}.php e.g single-testimonial.php

And for a archive page it would be archive-{posttype}.php e.g archive-testimonial.php

If for some reason your archive page doesn’t show or your getting a white screen, here is a few things you can try.

If your having an problems or issues let me know in the comments and I will gladly assist anyway I can.