{"id":1293373,"date":"2024-02-20T17:43:46","date_gmt":"2024-02-20T17:43:46","guid":{"rendered":"https:\/\/rankmath.com\/?p=1293373"},"modified":"2025-09-30T01:48:35","modified_gmt":"2025-09-30T01:48:35","slug":"custom-post-type","status":"publish","type":"post","link":"https:\/\/rankmath.com\/nl\/blog\/custom-post-type\/","title":{"rendered":"Hoe u een aangepast berichttype kunt maken in WordPress"},"content":{"rendered":"<p>WordPress is een krachtig contentmanagementsysteem (CMS) dat veel flexibiliteit en aanpassingsmogelijkheden biedt.&nbsp;<\/p>\n\n\n\n<p>Soms voldoen de standaardberichten en -pagina&#039;s echter mogelijk niet aan uw behoeften.&nbsp;<\/p>\n\n\n\n<p>Dat is waar aangepaste berichttypen een rol spelen: ze geven je de sleutel om unieke inhoud te presenteren, precies zoals jij dat wilt.&nbsp;<\/p>\n\n\n\n<p>In dit stapsgewijze bericht begeleiden we u bij het maken van een aangepast berichttype, leggen we de voordelen uit en helpen we u deze als een professional weer te geven. <\/p>\n\n\n\n<p>Dus, zonder verder oponthoud, laten we aan de slag gaan!<\/p>\n\n\n\n<!--more-->\n\n\n\n<div id=\"toc\">\n    <h2>Inhoudsopgave<\/h2>\n    <ol>\n        <li><a href=\"#what-is-custom-post-type\">What is a Custom Post Type?<\/a><\/li>\n        <li><a href=\"#why-to-create-custom-post-type\">Why Would You Want to Create a Custom Post Type?<\/a>\n        <\/li><li><a href=\"#custom-vs-default\">Custom vs. Default WordPress Post Types<\/a>\n<\/li><li><a href=\"#how-to-create-custom-post-type\">How to Create a Custom Post Type in WordPress<\/a>\n            <ul>\n                <li><a href=\"#plugin\">Create a Custom Post Type Using a Plugin<\/a><\/li>\n                <li><a href=\"#manual\">Creating a Custom Post Type Manually<\/a><\/li>\n                \n            <\/ul>\n        <\/li>\n        <li><a href=\"#conclusion\">Conclusie<\/a><\/li>\n    <\/ol>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-custom-post-type\"><span class=\"number\">1<\/span>  What is a Custom Post Type?<\/h2>\n\n\n\n<p>A custom post type is a way to define a new type of content in WordPress. By default, WordPress comes with several <a href=\"https:\/\/wordpress.org\/documentation\/article\/what-is-post-type\/#default-post-types\" data-schema-attribute=\"mentions\" target=\"_blank\" rel=\"noopener\">post types<\/a>, such as<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Posts<\/li>\n\n\n\n<li>Pagina&#039;s&nbsp;<\/li>\n\n\n\n<li>Attachments<\/li>\n\n\n\n<li>Revisions<\/li>\n\n\n\n<li>Navigation menus<\/li>\n\n\n\n<li>Custom CSS<\/li>\n\n\n\n<li>Changesets<\/li>\n<\/ul>\n\n\n\n<p>However, you can create a custom post type that will allow you to register a new content type with its data fields, editing interface, display options, and <a href=\"https:\/\/rankmath.com\/kb\/wordpress-permalinks\/\">permalink structure<\/a>.&nbsp;<\/p>\n\n\n\n<p>For example, you may want a custom post type for testimonials, with fields for a quote, author name, and company. Or you can choose a custom event post type with fields for date, location, image, etc.&nbsp;<\/p>\n\n\n\n<p>With custom post types, you can create your content types with unique attributes and taxonomies.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-to-create-custom-post-type\"><span class=\"number\">2<\/span>  Why Would You Want to Create a Custom Post Type?<\/h2>\n\n\n\n<p>Here are a few more reasons you might want custom post types in WordPress:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>&nbsp;To organize different types of content on your website.<\/li>\n\n\n\n<li>&nbsp;To have more control over the display of your content.<\/li>\n\n\n\n<li>&nbsp;To enable different sets of features for different types of content.<\/li>\n\n\n\n<li>&nbsp;To create a unique layout or functionality for a specific type of content.<\/li>\n\n\n\n<li>&nbsp;To improve the user experience by making finding and <a href=\"https:\/\/rankmath.com\/blog\/website-navigation\/\">navigating content<\/a> easier.<\/li>\n\n\n\n<li>&nbsp;To customize the WordPress admin panel for different types of content.<\/li>\n\n\n\n<li>&nbsp;To enhance the <a href=\"https:\/\/rankmath.com\/blog\/best-seo-practices\/\">SEO<\/a> of your website by structuring your content in a more meaningful way.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"custom-vs-default\"><span class=\"number\">3<\/span>  Custom vs. Default WordPress Post Types<\/h2>\n\n\n\n<p>Now that we&#8217;ve covered the basics let&#8217;s look at the differences between custom and default WordPress post types.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Custom Post Types<\/strong><\/td><td><strong>Default Post Types<\/strong><\/td><\/tr><tr><td>Created by the user<\/td><td>Predefined by WordPress<\/td><\/tr><tr><td>Can have unique attributes and taxonomies&nbsp;<\/td><td>Limited to pre-existing attributes and taxonomies<\/td><\/tr><tr><td>Provides flexibility and customization&nbsp;<\/td><td>Limited customization options<\/td><\/tr><tr><td>Allows for unique templates and layouts<\/td><td>Limited template options<\/td><\/tr><tr><td>Can be used for specific content types&nbsp;<\/td><td>General-purpose content types<\/td><\/tr><tr><td>Requires coding or plugin installation<\/td><td>Built-in functionality<\/td><\/tr><tr><td>Requires manual setup and configuration&nbsp;<\/td><td>Ready to use out of the box<\/td><\/tr><tr><td>Enhances user experience with structured content<\/td><td>Standard formatting for content<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-create-custom-post-type\"><span class=\"number\">4<\/span>  How to Create a Custom Post Type in WordPress<\/h2>\n\n\n\n<p>You can create a custom post type with the help of a plugin, or you can manually create one.<\/p>\n\n\n\n<p>Let&#8217;s explore both methods in detail.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"plugin\"><span class=\"number\">4.1<\/span>  Create a Custom Post Type Using a Plugin<\/h3>\n\n\n\n<p>Using a plugin to create custom post types offers a convenient solution for those who prefer not to modify code or seek a quicker and simpler method.&nbsp;<\/p>\n\n\n\n<p>To begin, install and activate the <a href=\"https:\/\/wordpress.org\/plugins\/custom-post-type-ui\/\" target=\"_blank\" rel=\"noopener\">Custom Post Type UI<\/a> plugin. You can find detailed instructions on <a href=\"https:\/\/rankmath.com\/blog\/how-to-install-wordpress-plugin\/\">how to install a WordPress plugin<\/a> in our step-by-step guide.<\/p>\n\n\n\n<p>Once activated, access the <strong>CPT UI \u2192 Add\/Edit Post Types<\/strong> section from your WordPress dashboard. This will direct you to the &#8216;Add New Post Type&#8217; tab.<\/p>\n\n\n\n<p>Within this tab, you can start customizing the <strong>Basic settings<\/strong>. Here, you can specify the custom post&#8217;s URL, consisting of alphabetic or numeric characters.<\/p>\n\n\n\n<p>You&#8217;ll also need to provide plural and singular menu names for your custom post type.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"2242\" height=\"1220\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/add-post-type.jpeg\" alt=\"Add Custom Post Type\" class=\"wp-image-1293707\" \/><\/figure>\n\n\n\n<p>You can click the <strong>Populate additional labels based on chosen labels<\/strong> link if desired. This automatically fills in the additional label fields below, saving you time.<\/p>\n\n\n\n<p>Next, you can save your changes by clicking the <strong>Add Post Type <\/strong>button or proceed to the following setting, the <strong>Additional Labels<\/strong> section.<\/p>\n\n\n\n<p>If you didn&#8217;t use the Auto-populate labels feature, you can manually enter a description for your post type and provide other labels.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"2248\" height=\"1228\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/additional-labels.jpeg\" alt=\"Additional labels\" class=\"wp-image-1293708\" \/><\/figure>\n\n\n\n<p>These labels will be used throughout the WordPress user interface when managing content within the designated post type.<\/p>\n\n\n\n<p>Moving on to the general settings, this is where you&#8217;ll configure the attributes and structures for your custom post type. A brief description accompanies each option to help you select appropriately.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"2002\" height=\"1240\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/settings-1.jpeg\" alt=\"Algemene instellingen\" class=\"wp-image-1293710\" \/><\/figure>\n\n\n\n<p>In the final section of the settings, you&#8217;ll see the support and taxonomy options. Check the boxes for the features you want your custom post type to support, and repeat the process in the <strong>Taxonomies <\/strong>section.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1710\" height=\"1260\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/taxonomies.jpeg\" alt=\"Taxonomies\" class=\"wp-image-1293712\" \/><\/figure>\n\n\n\n<p>Once you&#8217;re happy with your settings, click the <strong>Add Post Type<\/strong> knop om uw wijzigingen op te slaan.<\/p>\n\n\n\n<p>After saving, you&#8217;ll notice your newly created custom post type displayed as one of the menu items in WordPress, as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1336\" height=\"588\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/my-events.jpeg\" alt=\"My Events section\" class=\"wp-image-1293717\" \/><\/figure>\n\n\n\n<p>Now, let&#8217;s discuss the manual method.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"manual\"><span class=\"number\">4.2<\/span>  Creating a Custom Post Type Manually<\/h3>\n\n\n\n<p>If you prefer manually creating a custom post type, it involves editing your theme&#8217;s functions.php file. <\/p>\n\n\n\n<p>Typically, you can access the functions.php file by accessing your WordPress installation&#8217;s files via FTP or the WordPress dashboard.&nbsp;<\/p>\n\n\n\n<p>However, since you can lose the code after updating your theme, it is recommended to use a WordPress snippet plugin like WPCode.<\/p>\n\n\n\n<p>To proceed, you&#8217;ll need to install and activate the <a href=\"https:\/\/wordpress.org\/plugins\/insert-headers-and-footers\/\" target=\"_blank\" rel=\"noopener\">WPCode plugin<\/a>.&nbsp;<\/p>\n\n\n\n<p>Once activated, go to <strong>Code Snippets \u2192 Add Snippet <\/strong>in your WordPress dashboard. Hover your mouse over &#8216;Add Your Custom Code (New Snippet),&#8217; then click the <strong>Use Snippet <\/strong>knop.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1682\" height=\"566\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/use-code-snippet.jpeg\" alt=\"click Use snippet\" class=\"wp-image-1293719\" \/><\/figure>\n\n\n\n<p>This will take you to the \u2018Create Custom Snippet\u2019 page. Next, give your snippet a title, toggle the switch to <strong>Active, <\/strong>and then change the code type to <strong>PHP Snippet<\/strong>, as illustrated below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1680\" height=\"754\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/custom-code-snippet.jpeg\" alt=\"Custom snippet\" class=\"wp-image-1293725\" \/><\/figure>\n\n\n\n<p>After that, paste the following code into the \u2018Code Preview\u2019 area.&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Function to register our custom post type\nfunction create_posttype() {\n  \n    register_post_type( 'events',\n    \/\/ CPT Options\n        array(\n            'labels' =&gt; array(\n                'name' =&gt; __( 'Events' ),\n                'singular_name' =&gt; __( 'Event' )\n            ),\n            'public' =&gt; true,\n            'has_archive' =&gt; true,\n            'rewrite' =&gt; array('slug' =&gt; 'events'),\n            'show_in_rest' =&gt; true,\n  \n        )\n    );\n}\n\/\/ Hook our function to 'init' \nadd_action( 'init', 'create_posttype' );<\/code><\/pre>\n\n\n\n<p>The code provided creates a basic custom post type named &#8216;Events&#8217; that will be displayed in your admin menu and is compatible with any theme.<\/p>\n\n\n\n<p>If you only need a simple custom post type, you can replace &#8216;events&#8217; and &#8216;Events&#8217; with your desired slug and CPT name, then click the <strong>Bijwerken <\/strong>knop.<\/p>\n\n\n\n<p>However, if you require additional options for your custom post type, you can use the following code instead of the previous one.<\/p>\n\n\n\n<p>This code enhances the &#8216;Events&#8217; custom post type with various options, including support for revisions, featured images, custom fields, and the association with a custom taxonomy named &#8216;location.&#8217;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*\n* Creating a function to create our custom post type  \n*\/\n\nfunction custom_post_type() {\n\n  \/\/ Set UI labels for Custom Post Type\n  $labels = array(\n    'name' =&gt; _x( 'Events', 'Post Type General Name', 'astra' ),\n    'singular_name' =&gt; _x( 'Event', 'Post Type Singular Name', 'astra' ),\n    'menu_name' =&gt; __( 'Events', 'astra' ),\n    'parent_item_colon' =&gt; __( 'Parent Event', 'astra' ),\n    'all_items' =&gt; __( 'All Events', 'astra' ),\n    'view_item' =&gt; __( 'View Event', 'astra' ),\n    'add_new_item' =&gt; __( 'Add New Event', 'astra' ),\n    'add_new' =&gt; __( 'Add New', 'astra' ),\n    'edit_item' =&gt; __( 'Edit Event', 'astra' ),\n    'update_item' =&gt; __( 'Update Event', 'astra' ),\n    'search_items' =&gt; __( 'Search Event', 'astra' ),\n    'not_found' =&gt; __( 'Not Found', 'astra' ),\n    'not_found_in_trash' =&gt; __( 'Not found in Trash', 'astra' ),\n  );\n\n  \/\/ Set other options for Custom Post Type\n  $args = array(\n    'label' =&gt; __( 'events', 'astra' ),\n    'description' =&gt; __( 'Event listings', 'astra' ),\n    'labels' =&gt; $labels,\n\n    \/\/ Features this CPT supports in Post Editor\n    'supports' =&gt; array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),\n\n    \/\/ Taxonomy associated with this CPT\n    'taxonomies' =&gt; array( 'location' ), \n\n    \/* A hierarchical CPT is like Pages and can have\n       Parent and child items. A non-hierarchical CPT  \n       is like Posts. \n    *\/\n    'hierarchical' =&gt; false,\n    \n    'public' =&gt; true,\n    'show_ui' =&gt; true,    \n    'show_in_menu' =&gt; true,\n    'show_in_nav_menus' =&gt; true,\n    'show_in_admin_bar' =&gt; true,    \n    'menu_position' =&gt; 5,    \n    'can_export' =&gt; true,\n    'has_archive' =&gt; true,    \n    'exclude_from_search' =&gt; false,\n    'publicly_queryable' =&gt; true,        \n    'capability_type' =&gt; 'post',    \n    'show_in_rest' =&gt; true,\n  );\n\n  \/\/ Registering the Custom Post Type\n  register_post_type( 'events', $args );\n\n}\n\n\/* Hook into the 'init' action so that the function\n   containing our CPT registration is not  \n   unnecessarily executed.\n*\/\n\nadd_action( 'init', 'custom_post_type', 0 );<\/code><\/pre>\n\n\n\n<p>In this code, the hierarchical custom post type value is set to <code>vals<\/code>. To make the custom post type display like pages instead of posts, you can change this value to <code>true<\/code>.&nbsp;&nbsp;<\/p>\n\n\n\n<p>The text domain used in the code is &#8216;astra.&#8217; So, to use your theme&#8217;s text domain if it supports translation, go to <strong>Appearance \u2192 Theme File Editor <\/strong>in the admin panel.&nbsp;<\/p>\n\n\n\n<p>As shown below, navigate to style.css to see your theme&#8217;s text domain.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"1668\" height=\"630\" src=\"https:\/\/rankmath.com\/wp-content\/uploads\/2024\/02\/style-css.jpeg\" alt=\"Navigate to style.css\" class=\"wp-image-1293728\" \/><\/figure>\n\n\n\n<p>Remember to keep the code you want active in the WPCode plugin and click the <strong>Bijwerken <\/strong>button after making changes.&nbsp;<\/p>\n\n\n\n<p class=\"takeaway yellow\"><strong>Opmerking:<\/strong> Avoid combining two snippets that register the same custom post type, which causes WordPress errors. For additional post types, create a new snippet for each one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><span class=\"number\">5<\/span>  Conclusie<\/h2>\n\n\n\n<p>Adding custom post types to your WordPress website can significantly improve its functionality and organization.&nbsp;<\/p>\n\n\n\n<p>Following the steps in this guide, you can easily create custom post types that cater to your specific needs.&nbsp;<\/p>\n\n\n\n<p>Here are some tips to help you:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Keep your audience in mind when designing custom post types. Ensure they are easy to locate, navigate, and understand.<\/li>\n\n\n\n<li>Don&#8217;t hesitate to experiment with different configurations to find what works best for your website.<\/li>\n\n\n\n<li>Before applying any code to your live website, it&#8217;s recommended to test it on a <a href=\"https:\/\/rankmath.com\/blog\/how-to-create-staging-site\/\">staging environment<\/a> to avoid potential issues.<\/li>\n\n\n\n<li>Altijd<a href=\"https:\/\/rankmath.com\/blog\/backup-wordpress-site\/\"> maak een back-up van je website<\/a> before making any changes to ensure you can restore it if needed.<\/li>\n<\/ul>\n\n\n\n<p>With this, you can elevate your WordPress website to new heights with effort and experimentation.&nbsp;<\/p>\n\n\n\n<p>If you found this post helpful, please share your feedback by <a href=\"https:\/\/twitter.com\/rankmathseo\" target=\"_blank\" rel=\"noopener\">Twitteren @rankmathseo.<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>WordPress is a powerful content management system (CMS) that offers many flexibility and customization options.&nbsp; However, sometimes, the default posts and pages may not meet your needs.&nbsp; That&#8217;s where custom post types come in &#8211; they give you the key to showcase unique content just how you want it.&nbsp; In this step-by-step post, we will [&hellip;]<\/p>","protected":false},"author":37,"featured_media":1293519,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[136],"tags":[],"class_list":{"0":"post-1293373","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-wp-tutorials"},"_links":{"self":[{"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/posts\/1293373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/comments?post=1293373"}],"version-history":[{"count":3,"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/posts\/1293373\/revisions"}],"predecessor-version":[{"id":1610217,"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/posts\/1293373\/revisions\/1610217"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/media\/1293519"}],"wp:attachment":[{"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/media?parent=1293373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/categories?post=1293373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rankmath.com\/nl\/wp-json\/wp\/v2\/tags?post=1293373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}