2 min

How to add a Custom Post Type to WordPress with PHP

To add a custom message type in WordPress using PHP, you can follow these steps.

Add custom message type to Wordpress using PHP

To add a custom message type in WordPress using PHP, you can follow the following steps:

  1. Create a new PHP file and name it, for example, "custom-post-type.php".
  2. Add the following code to the beginning of the file to begin registering your custom message type:
function register_custom_post_type() {
    // code om de aangepaste berichtentype te registreren
add_action('init', 'register_custom_post_type');
  1. Add the following code to the "register_custom_post_type" function to register the custom message type:
$labels = array(
    'name' => _x('Name of your message type', 'post type general name'),
    'singular_name' => _x('Name of the single post', 'post type singular name'),
    'add_new' => _x('Add new post', 'new post'),
    'add_new_item' => __('add new post'),
    'edit_item' => __('Edit post'),
    'new_item' => __('New post'),
    'view_item' => __('View post'),
    'search_items' => __('Search posts'),
    'not_found' => __('No posts found'),
    'not_found_in_trash' => __('No messages found in trash'),
    'parent_item_colon' => ''
$args = array(
    'labels' => $labels,
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'query_var' => true,
    'rewrite' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'menu_position' => null,
    'supports' => array('title','editor','author','thumbnail','excerpt','comments')
  1. Make sure the PHP file is inserted into your WordPress site by placing it in the "plugins" folder or by adding it to your "functions.php" file in your active theme.
  2. After you upload and activate the file, you should see a new option in the WordPress admin area that allows you to create and edit posts of the custom post type.

N.B. This code is an example only and will need to be modified as you see fit.

Rens Hageman

We help companies in

Book A Free Strategy Call

Book a 100% free, no-obligation strategy call with one of our experts (worth €667). This is exclusively for people who are serious about growing their business. Still a few free spots available in March.

100% value
100% free
100% no obligation