Menü schliessen
Created: February 18th 2021
Last updated: April 8th 2021
Categories: Php,  Wordpress
Author: Tim Fürer

WordPress: Declare a Custom Post Type

Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

In this guide, I'll show you how to declare a Custom Post Type in the functions.php file of your WordPress-Theme.

Start out by declaring the function:

function create_custom_post_type() {

Create this "$args" variable and include the following arguments for defining the Custom Post Type:

$args = array(
	'labels' => array(
		'name' => __( 'instert_name'),
		'singular_name' => __( 'insert_single_name'),
		'menu_name' => __('instert_menu_name')
	),
	'description' => 'insert_description',
	'public' => true,
	'menu_position' => 5,
	'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
	'has_archive' => true
);

You can look up other arguments you can add in order to further customize your Custom Post Type in the WordPress Documentation.

Now, finish up the function by registering the Post Type together with the "$args" variable you've just created like this:

register_post_type( 'insert_custom_post_type_name', $args );
}

Hook the function with this method:

add_action( 'init', 'create_custom_post_type' );

Your end product might look something along the lines of this:

Example of code

And shows up in WordPress like this:

Example of WordPress Menu

A further guide on making Custom Taxonomies for your Custom Post Type is available here.