{"id":7044,"date":"2020-02-03T13:13:15","date_gmt":"2020-02-03T13:13:15","guid":{"rendered":"https:\/\/www.hostinger.com\/tutorials\/?p=7044"},"modified":"2026-03-09T19:19:20","modified_gmt":"2026-03-09T19:19:20","slug":"wordpress-custom-post-types","status":"publish","type":"post","link":"\/ng\/tutorials\/wordpress-custom-post-types\/","title":{"rendered":"How to create a WordPress custom post type: what it is and its customization"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>WordPress has multiple post types to help you organize your website&rsquo;s content. You can easily create a chronological blog or display static pages with them.<\/p><p>However, the built-in post types may not be sufficient for large websites with diverse content. In that case, you need to create your own post type.<\/p><p>This article will explain how to create a custom post type in WordPress. You will also learn how to customize it to expand its functionality.<\/p><p class=\"has-text-align-center\"><a href=\"https:\/\/assets.hostinger.com\/content\/tutorials\/pdf\/Mega-WordPress-Cheat-EN.pdf\">Download all-in-one WordPress cheat sheet<\/a><\/p><p>\n\n\n\n<div class=\"protip\"><div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                   What Is WordPress Custom Post Type?\n                <\/p>\n            <\/div>\n            <p class=\"protip__content\"> WordPress custom post type is an additional content category users create to organize their website content. It is useful if your WordPress website has diverse content that doesn&rsquo;t belong to WordPress&rsquo;s default post types.<\/p><\/div>\n\n\n\n<\/p><p>While you can assign categories to organize your content, your posts will appear in one list when grouped into the same post type. This makes tracking your posts more difficult.<\/p><p>By default, WordPress has seven post types:<\/p><ol class=\"wp-block-list\">\n<li><strong>Posts<\/strong> &ndash; category for regular posts. Typical content of this type includes a blog post.<\/li>\n\n\n\n<li><strong>Pages<\/strong> &ndash; displays static content that is not listed by date.<\/li>\n\n\n\n<li><strong>Attachments<\/strong> &ndash; all the website media, including images, videos, or PDF files.<\/li>\n\n\n\n<li><strong>Revisions <\/strong>&ndash; saved versions of all post types.<\/li>\n\n\n\n<li><strong>Navigation Menus <\/strong>&ndash; list of links your website visitors can use to find specific information.<\/li>\n\n\n\n<li><strong>Custom CSS <\/strong>&ndash; type that you can modify to customize your WordPress theme.<\/li>\n\n\n\n<li><strong>Changesets <\/strong>&ndash; the track of changes made in the customizer.<\/li>\n<\/ol><p>WordPress custom post types allow you to choose a particular section for your content. You can quickly group content without choosing categories and easily track posts in different sections.<\/p><p>Custom post types in WordPress also offer several customization options. This allows you to expand their functionality beyond the default posts.<\/p><p>For instance, you can move the custom post type menu, change the edit screen&rsquo;s appearance, and enable features like featured images or excerpts.<\/p><h2 class=\"wp-block-heading\" id=\"h-elements-of-a-wordpress-custom-post-type\">Elements of a WordPress Custom Post Type<\/h2><p>Before creating custom post types, you must understand the terms<strong> array <\/strong>and <strong>element<\/strong>. They are essential parts of your custom post type&rsquo;s code.<\/p><p>An <strong>array <\/strong>is a data structure that stores key and value pairs known as <strong>elements<\/strong>. In this case, it reserves the properties of the custom post type.<\/p><p>To create a custom WordPress post type, there are three arrays containing different elements &ndash; <strong>$args<\/strong>, <strong>$labels<\/strong>, and <strong>$supports<\/strong>. The associative array <strong>$args<\/strong> is short for arguments, which include various key-value pairs, including:<\/p><ul class=\"wp-block-list\">\n<li><strong>description<\/strong> &ndash; a short and descriptive summary of the post type. You can only display it in the post type&rsquo;s template.<\/li>\n\n\n\n<li><strong>public<\/strong> &ndash; changes WordPress custom post types&rsquo; visibility to authors and visitors. Choose <strong>TRUE<\/strong> to make it appear in the WordPress Dashboard and visitors&rsquo; custom query.<\/li>\n\n\n\n<li><strong>menu_position<\/strong> &ndash; defines the new post type&rsquo;s location in the WordPress admin menu. Refer to the <a href=\"https:\/\/developer.wordpress.org\/reference\/\">WordPress codex page<\/a> for its value and positions.<\/li>\n\n\n\n<li><strong>has_archive<\/strong> &ndash; defines the custom post type archives, URL structure, and slug name based on parameter 1 of<strong> register_post_types()<\/strong>.<\/li>\n\n\n\n<li><strong>show_in_admin_bar <\/strong>&ndash; alters the post type&rsquo;s visibility in the upper admin bar under the <strong>+New<\/strong> section.<\/li>\n\n\n\n<li><strong>show_in_nav_menus<\/strong> &ndash; changes whether you can add posts of this type to navigation menus created via the <strong>Appearance<\/strong> &rarr; <strong>Menus<\/strong>.<\/li>\n\n\n\n<li><strong>query_var <\/strong>&ndash; sets whether site visitors can enter a post&rsquo;s type and title as a query in the URL to view it.<\/li>\n<\/ul><p>In addition to the elements, <strong>$args<\/strong> holds the <strong>$labels <\/strong>and <strong>$supports<\/strong> array containing different key-value pairs. We recommend creating a separate <strong>$labels<\/strong> variable to keep all the key and value pairs to make the code cleaner and easier to understand<\/p><p>The <strong>$label<\/strong> array defines the custom post type&rsquo;s text and holds the following keys:<\/p><ul class=\"wp-block-list\">\n<li><strong>name<\/strong> &ndash; the general plural name for the post type<\/li>\n\n\n\n<li><strong>singular_name<\/strong> &ndash; the name for a single post of the custom type<\/li>\n\n\n\n<li><strong>add_new<\/strong> &ndash; replaces the &lsquo;Add New&rsquo; text<\/li>\n\n\n\n<li><strong>add_new_item<\/strong> &ndash; changes the &lsquo;Add New Post&rsquo; text<\/li>\n\n\n\n<li><strong>edit_item<\/strong> &ndash; adjusts the &lsquo;Edit Post&rsquo; text<\/li>\n\n\n\n<li><strong>featured_image <\/strong>&ndash; modifies &lsquo;Featured Image&rsquo; in the post editor<\/li>\n\n\n\n<li><strong>set_featured_image<\/strong> &ndash; replaces &lsquo;Set Featured Image&rsquo;<\/li>\n\n\n\n<li><strong>menu_name <\/strong>&ndash; alters the text of the top-level link. The default text for the link is the name key<\/li>\n<\/ul><p>Meanwhile, the <strong>$supports <\/strong>array contains elements that define the custom post type&rsquo;s features. The <strong>TRUE<\/strong> value enables the following features:<\/p><ul class=\"wp-block-list\">\n<li>title<\/li>\n\n\n\n<li>editor<\/li>\n\n\n\n<li>author<\/li>\n\n\n\n<li>thumbnail<\/li>\n\n\n\n<li>excerpt<\/li>\n\n\n\n<li>trackbacks<\/li>\n\n\n\n<li>custom-fields<\/li>\n\n\n\n<li>comments<\/li>\n\n\n\n<li>revisions<\/li>\n\n\n\n<li>page-attributes<\/li>\n\n\n\n<li>post-formats<\/li>\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-how-to-create-a-wordpress-custom-post-type\">How to Create a WordPress Custom Post Type<\/h2><p>There are three different ways to add custom post types in WordPress, and each has its pros and cons:<\/p><ul class=\"wp-block-list\">\n<li><strong>Using a normal plugin<\/strong> &ndash; most simple, but the custom post type will be deleted if you uninstall or deactivate the plugin.<\/li>\n\n\n\n<li><strong>Editing the theme&rsquo;s functions.php file<\/strong> &ndash; doesn&rsquo;t require an additional tool, but this method doesn&rsquo;t preserve the data after the theme update.<\/li>\n\n\n\n<li><strong>Creating a <\/strong><a href=\"https:\/\/developer.wordpress.org\/plugins\/\"><strong>site-specific plugin <\/strong><\/a>&ndash; preserves the data and is highly customizable but requires technical skills.<\/li>\n<\/ul><p>In this article, we will use the third method. Before proceeding, we recommend you read our tutorial about <a href=\"\/ng\/tutorials\/how-to-create-wordpress-plugin\/\">how to create a WordPress plugin<\/a> to learn more about the custom code.<\/p><p>To create custom post types, use<strong> <\/strong>the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/register_post_type\/\">register_post_type()<\/a> function. This takes two parameters &ndash; the <strong>custom post type name<\/strong> and the <strong>$args <\/strong>array.<\/p><p>The plugin&rsquo;s code should also contain custom functions that call <strong>register_post_type()<\/strong>. Remember to hook these functions to the <strong>init <\/strong>action hook to allow the custom post type to register properly.<\/p><p>To avoid conflict with other plugins, your custom function should have a prefix like <strong>ht_<\/strong>.<\/p><p>Here is a code example for a <strong>Custom Article <\/strong>post type plugin:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/*\nPlugin Name: Custom Post Types\nDescription: Add post types for custom articles\nAuthor: Hostinger Dev\n*\/\n\/\/ Hook ht_custom_post_custom_article() to the init action hook\nadd_action( 'init', 'ht_custom_post_custom_article' );\n\/\/ The custom function to register a custom article post type\nfunction ht_custom_post_custom_article() {\n    \/\/ Set the labels. This variable is used in the $args array\n    $labels = array(\n        'name'               =&gt; __( 'Custom Articles' ),\n        'singular_name'      =&gt; __( 'Custom Article' ),\n        'add_new'            =&gt; __( 'Add New Custom Article' ),\n        'add_new_item'       =&gt; __( 'Add New Custom Article' ),\n        'edit_item'          =&gt; __( 'Edit Custom Article' ),\n        'new_item'           =&gt; __( 'New Custom Article' ),\n        'all_items'          =&gt; __( 'All Custom Articles' ),\n        'view_item'          =&gt; __( 'View Custom Article' ),\n        'search_items'       =&gt; __( 'Search Custom Article' ),\n        'featured_image'     =&gt; 'Poster',\n        'set_featured_image' =&gt; 'Add Poster'\n    );\n\/\/ The arguments for our post type, to be entered as parameter 2 of register_post_type()\n    $args = array(\n        'labels'            =&gt; $labels,\n        'description'       =&gt; 'Holds our custom article post specific data',\n        'public'            =&gt; true,\n        'menu_position'     =&gt; 5,\n        'supports'          =&gt; array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ),\n        'has_archive'       =&gt; true,\n        'show_in_admin_bar' =&gt; true,\n        'show_in_nav_menus' =&gt; true,\n        'query_var'         =&gt; true,\n    );\n    \/\/ Call the actual WordPress function\n    \/\/ Parameter 1 is a name for the post type\n    \/\/ Parameter 2 is the $args array\n    register_post_type('article', $args);\n}<\/pre><p>Note that the code may vary depending on the custom post type. Once you finish writing the code, follow these steps to turn it into a plugin:<\/p><ol class=\"wp-block-list\">\n<li>Copy and paste the code into a text editor. For example, we will use Windows <strong>Notepad<\/strong>.<\/li>\n\n\n\n<li>Save the file. Name the file <strong>custom-post-type.php <\/strong>and select <strong>All Files <\/strong>from the <strong>Save as type <\/strong>dropdown menu.<\/li>\n\n\n\n<li>Click <strong>Save<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-code-saved-as-a-php-file-with-Notepad.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"771\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-code-saved-as-a-php-file-with-Notepad.png\/w=1024,h=1024,fit=scale-down\" alt=\"The custom plugin code saved as a php file with Notepad\n\" class=\"wp-image-73110\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-code-saved-as-a-php-file-with-Notepad.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-code-saved-as-a-php-file-with-Notepad.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-code-saved-as-a-php-file-with-Notepad.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-code-saved-as-a-php-file-with-Notepad.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-code-saved-as-a-php-file-with-Notepad.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"4\">\n<li>Open your FTP client or hosting account&rsquo;s file manager. For Hostinger users, go to your <strong>hPanel <\/strong>&rarr; <strong>Hosting<\/strong> &rarr; <strong>Manage<\/strong> <strong>&rarr;<\/strong> <strong>Files &rarr;<\/strong> <strong>File Manager<\/strong>.<\/li>\n\n\n\n<li>Inside the<strong> File Manager<\/strong>, navigate to <strong>public_html <\/strong>&rarr;<strong> wp-content <\/strong>&rarr;<strong> plugins<\/strong>.<\/li>\n\n\n\n<li>Create a new folder and name it <strong>custom-post-type<\/strong>.<\/li>\n\n\n\n<li>Paste the<strong> <\/strong>file into the folder.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-php-file-inside-the-website_s-plugin-folder.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"550\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-php-file-inside-the-website_s-plugin-folder.png\/w=1024,h=1024,fit=scale-down\" alt=\"The custom plugin php file inside the website's plugin folder\n\" class=\"wp-image-73111\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-php-file-inside-the-website_s-plugin-folder.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-php-file-inside-the-website_s-plugin-folder.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-php-file-inside-the-website_s-plugin-folder.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-custom-plugin-php-file-inside-the-website_s-plugin-folder.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"8\">\n<li>Log in to your WordPress dashboard. Go to <strong>Plugins <\/strong>&rarr; <strong>Installed Plugins<\/strong>.<\/li>\n\n\n\n<li>Find the <strong>Custom Post Type <\/strong>plugin and click <strong>Activate<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Custom-post-type-plugin-activation-setting.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"600\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Custom-post-type-plugin-activation-setting.png\/w=1024,h=1024,fit=scale-down\" alt=\"Custom Post Type plugin activation setting\n\" class=\"wp-image-73112\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Custom-post-type-plugin-activation-setting.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Custom-post-type-plugin-activation-setting.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Custom-post-type-plugin-activation-setting.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Custom-post-type-plugin-activation-setting.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Custom-post-type-plugin-activation-setting.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"10\">\n<li>Refresh the page. You should see the <strong>Custom Article <\/strong>post type on your WordPress admin menu.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-post-type-in-the-WordPress-sidebar.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"417\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-post-type-in-the-WordPress-sidebar.png\/w=1024,h=1024,fit=scale-down\" alt=\"A custom post type in the WordPress sidebar\n\" class=\"wp-image-73113\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-post-type-in-the-WordPress-sidebar.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-post-type-in-the-WordPress-sidebar.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-post-type-in-the-WordPress-sidebar.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-post-type-in-the-WordPress-sidebar.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-post-type-in-the-WordPress-sidebar.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><p>You may create an unlimited number of custom post types. However, too many custom post types can slow the <a href=\"\/ng\/tutorials\/wordpress-rest-api\/\">REST API<\/a> discovery and complicate the admin bar.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-customize-new-post-type\">How to Customize New Post Type<\/h2><p>You may need to customize your new post type to differentiate it from other content. Before customizing, you should create template files in your active theme&rsquo;s directory.<\/p><p>You need two template files for customization &ndash;<strong> single-{post_type}.php <\/strong>and <strong>archive-{post_type}.php<\/strong>. These are templates for an individual post entry and the custom type&rsquo;s archive page, respectively.<\/p><p>WordPress will use the default <strong>single.php <\/strong>and <strong>archive.php<\/strong> if you don&rsquo;t create these templates. Since all posts and archives refer to those two files, customizing them will change the entire site.<\/p><p>The best way to create template files is to duplicate your theme&rsquo;s existing <strong>single.php <\/strong>and <strong>archive.php <\/strong>files. This method keeps your site&rsquo;s theme structure and sets up the required template tag, simplifying the customization process.<\/p><p>Here are the steps to do so:<\/p><ol class=\"wp-block-list\">\n<li>Access your FTP client or hosting account&rsquo;s file manager.<\/li>\n\n\n\n<li>Locate your currently active theme folder. In our case, it is in <strong>\/public_html\/wp-content\/themes\/twentytwentyone<\/strong>.<\/li>\n\n\n\n<li>Copy the <strong>single.php<\/strong> and <strong>archive.php<\/strong> files and paste them outside that folder.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Single.php-and-Archive.php-outside-the-active-theme-folder.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"551\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Single.php-and-Archive.php-outside-the-active-theme-folder.png\/w=1024,h=1024,fit=scale-down\" alt=\"Single.php and Archive.php outside the active theme folder\n\" class=\"wp-image-73114\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Single.php-and-Archive.php-outside-the-active-theme-folder.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Single.php-and-Archive.php-outside-the-active-theme-folder.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Single.php-and-Archive.php-outside-the-active-theme-folder.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Single.php-and-Archive.php-outside-the-active-theme-folder.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"4\">\n<li>Rename them based on parameter 1 of your <strong>register_post_type()<\/strong>. Since our parameter 1 is <strong>article<\/strong>, the names are <strong>single-article.php<\/strong> and <strong>archive-article.php<\/strong>.<\/li>\n\n\n\n<li>Move the files back to the <strong>twentytwentyone<\/strong> folder.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Template-files-inside-the-currently-active-theme-folder.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"552\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Template-files-inside-the-currently-active-theme-folder.png\/w=1024,h=1024,fit=scale-down\" alt=\"Template files inside the currently active theme folder\n\" class=\"wp-image-73115\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Template-files-inside-the-currently-active-theme-folder.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Template-files-inside-the-currently-active-theme-folder.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Template-files-inside-the-currently-active-theme-folder.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Template-files-inside-the-currently-active-theme-folder.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"6\">\n<li>Repeat the second and third steps for other custom post type templates.<\/li>\n<\/ol><p><div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> Themes with the same structure for posts and pages won&rsquo;t have <strong>single.php<\/strong> and archive.php files. Such themes only use the <strong>singular.php file<\/strong>.\n            <\/p><\/div>\n\n\n\n<\/p><p>To customize the template files, download and edit them using a text editor. If you use Hostinger&rsquo;s <a href=\"\/ng\/web-hosting\">web hosting service<\/a>, edit them directly in the file manager.<\/p><p>Once you save the files, the changes should apply only to the custom type&rsquo;s archive page and individual entry.<\/p><h3 class=\"wp-block-heading\" id=\"h-adding-a-meta-box-to-a-custom-post-type\">Adding a Meta Box to a Custom Post Type<\/h3><p>The meta box is an editing screen window allowing users to add post metadata. It is useful for adding or modifying posts&rsquo; information, such as author details, publishing controls, and custom slug.<\/p><p>While WordPress comes with default meta boxes, you may need a specific one for your custom post type. For example, the <strong>Movies <\/strong>custom post type may require the <strong>Genre <\/strong>meta box.<\/p><p>Using a meta box helps you add metadata to your content more quickly. Instead of entering the value individually, you can click data from the meta box to input it.<\/p><p>To create a custom meta box, edit your theme&rsquo;s <strong>functions.php <\/strong>or site-specific plugin&rsquo;s code. In this tutorial, we will add the new meta box&rsquo;s custom code to the plugin&rsquo;s file.<\/p><p>Since the code varies depending on the meta box content and placement, refer to WordPress codex for more information. For this tutorial, we will explain how to build a custom <strong>Author <\/strong>meta box:<\/p><ol class=\"wp-block-list\">\n<li>Locate the <strong>custom-post-type.php<\/strong> file in your hosting file manager or FTP client.<\/li>\n\n\n\n<li>Double-click the file to open the editor screen. Alternatively, download and open the file in a text or code editor.<\/li>\n\n\n\n<li>Create an empty custom meta box by entering the following code:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Add meta box \nadd_action(\"add_meta_boxes\", \"add_author_meta_box\");\n\nfunction add_author_meta_box()\n{\n    add_meta_box(\n    \"author_meta_box\", \/\/ Meta box ID\n    \"Author Details\", \/\/ Meta box title\n    \"author_meta_box_callback\", \/\/ Meta box callback function\n    \"article\", \/\/ The custom post type parameter 1\n    \"side\", \/\/ Meta box location in the edit screen\n    \"high\" \/\/ Meta box priority\n); \n}\nfunction author_meta_box_callback()\n{ \n\twp_nonce_field(&lsquo;author-nonce&rsquo;, &lsquo;meta-box-nonce&rsquo;);\nglobal $post;\nplaceholder\n}<\/pre><ol class=\"wp-block-list\" start=\"4\">\n<li>Add the meta box&rsquo;s content by replacing the <strong>placeholder<\/strong> value. For this tutorial, we will add the author name and ID fields using the following code.<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Add meta box content \n ?&gt;\n\t&lt;th&gt;&lt;label for=\"athor_name_field\"&gt;Author Name&lt;\/label&gt;&lt;th&gt;\n\t&lt;td&gt;&lt;input \ntype=\"text\"\nid=\"author_name\" \nclass=\"regular-text\" \nname=&ldquo;Author_Name&rdquo; \nvalue=&ldquo;&rdquo; \n\/&gt; \n    &lt;td&gt; \n    &lt;th&gt;&lt;label for=\"author_id_field\"&gt;Author ID&lt;\/label&gt;&lt;th&gt;\n\t&lt;td&gt;&lt;input \ntype=\"text\" \nid=\"author_id\" \nclass=\"regular-text\"\nname=&ldquo;Author_ID&rdquo;\nValue=&rdquo;&rdquo;\n\/&gt; \n    &lt;td&gt; \n\t&lt;?php  <\/pre><ol class=\"wp-block-list\" start=\"5\">\n<li>At the bottom of the code, add the following snippet to save the entered values:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Save meta box data\nadd_action ( 'save_post', 'author_save_postdata');\nfunction author_save_postdata( $post_id ) {\n\n\/\/ If this is an autosave, our form has not been submitted\nif ( defined( 'DOING_AUTOSAVE' ) &amp;&amp; DOING_AUTOSAVE ) \nreturn $post_id;\n\n\t\/\/ Retrieve post id\n\tIf (&lsquo;article&rsquo; !== get_post_type() ) {\n\t\treturn $post_id\n}\n \t\/\/ Check the user's permissions\n   \tif ( 'page' == $_POST['post_type'] ) {\n  \nif ( ! current_user_can( 'edit_page', $post_id ) )\nreturn $post_id;\n  \n} else {\n  \nif ( ! current_user_can( 'edit_post', $post_id ) )\nreturn $post_id;\n}\n  \n\/* OK, it is safe to save the data now. *\/\n  \n\/\/ Sanitize user input.\n\n$mydata = sanitize_text_field( $_POST['Author_Name'] );\n\n$mydata = sanitize_text_field( $_POST['Author_ID'] );\n\n  \n\/\/ Update the meta field in the database.\n\nupdate_post_meta( $post_id, 'Author_Name', $_POST['Author_Name'] ); \n\nupdate_post_meta( $post_id, 'Author_ID', $_POST['Author_ID'] ); \n }<\/pre><ol class=\"wp-block-list\" start=\"6\">\n<li>In the file manager&rsquo;s code editor, click the <strong>disk icon<\/strong> on the top right to save the change. If you edit the code locally, save and re-upload the updated file.<\/li>\n<\/ol><p>The new meta box should appear if you open your custom post type&rsquo;s edit screen.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-author-details-meta-box-in-WordPress-post-edit-screen.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"616\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-author-details-meta-box-in-WordPress-post-edit-screen.png\/w=1024,h=1024,fit=scale-down\" alt=\"A custom author details meta box in the WordPress post edit screen\n\" class=\"wp-image-73117\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-author-details-meta-box-in-WordPress-post-edit-screen.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-author-details-meta-box-in-WordPress-post-edit-screen.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-author-details-meta-box-in-WordPress-post-edit-screen.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-author-details-meta-box-in-WordPress-post-edit-screen.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/A-custom-author-details-meta-box-in-WordPress-post-edit-screen.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><p>To ensure the meta box works properly, enter texts into the designated field and update the post. The entered value should appear in the custom fields.<\/p><p>If you need to become more familiar with PHP, use the <a href=\"https:\/\/wordpress.org\/plugins\/meta-box\/\">Meta Box<\/a> plugin to automatically generate the code. Since it only generates the meta boxes&rsquo; content code, you must write the <strong>add_metabox () <\/strong>function yourself.<\/p><p>After you download and install the plugin, follow these steps:<\/p><ol class=\"wp-block-list\">\n<li>On the WordPress sidebar, go to <strong>Plugins <\/strong>&rarr; <strong>Installed Plugins<\/strong>.<\/li>\n\n\n\n<li>Find the <strong>Meta Box <\/strong>plugin and click <strong>About<\/strong> <strong>&rarr; Go to Online Generator<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Meta-Box-plugin-in-WordPress_s-installed-plugins-menu.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"480\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Meta-Box-plugin-in-WordPress_s-installed-plugins-menu.png\/w=1024,h=1024,fit=scale-down\" alt=\"The Meta Box plugin in WordPress's installed plugins menu\n\" class=\"wp-image-73118\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Meta-Box-plugin-in-WordPress_s-installed-plugins-menu.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Meta-Box-plugin-in-WordPress_s-installed-plugins-menu.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Meta-Box-plugin-in-WordPress_s-installed-plugins-menu.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Meta-Box-plugin-in-WordPress_s-installed-plugins-menu.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Meta-Box-plugin-in-WordPress_s-installed-plugins-menu.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"3\">\n<li>Create a custom meta box.<\/li>\n\n\n\n<li>Click <strong>Generate Code<\/strong> &rarr; <strong>Copy<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Meta-Box-website_s-generate-custom-meta-box-code-button.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"694\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Meta-Box-website_s-generate-custom-meta-box-code-button.png\/w=1024,h=1024,fit=scale-down\" alt=\"Meta Box website's generate custom meta box code button\n\" class=\"wp-image-73119\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Meta-Box-website_s-generate-custom-meta-box-code-button.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Meta-Box-website_s-generate-custom-meta-box-code-button.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Meta-Box-website_s-generate-custom-meta-box-code-button.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Meta-Box-website_s-generate-custom-meta-box-code-button.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Meta-Box-website_s-generate-custom-meta-box-code-button.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"5\">\n<li>Paste the code to your <strong>functions.php <\/strong>or <strong>custom-post-type.php <\/strong>file.<\/li>\n<\/ol><p>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Pro Tip                <\/p>\n            <\/div>\n            <p class=\"protip__content\"> Use a plugin to <a href=\"\/ng\/tutorials\/wordpress\/how-to-add-php-code-to-wordpress-post-or-page\/\">add PHP code in WordPress posts or pages<\/a> directly via the admin dashboard. You don&rsquo;t have to create template files or use a separate text editor, improving workflow and minimizing errors. <\/p>\n                    <\/div>\n        \n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-display-custom-post-types-on-the-front-page\">How to Display Custom Post Types on the Front Page<\/h2><p>WordPress custom post types are not displayed on the front page by default. To enable them, write a new function that calls the set method of <a href=\"\/ng\/tutorials\/wordpress-wp_query\/\">WordPress&rsquo; WP_Query<\/a> object.<\/p><p>Here&rsquo;s an example:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Pin our custom function to the pre_get_posts action hook\nadd_action( 'pre_get_posts', 'add_article_to_frontpage' );\n\/\/ Alter the main query\nfunction add_article_to_frontpage( $query ) {\n if ( is_home() &amp;&amp; $query-&gt;is_main_query() ) {\n        $query-&gt;set( 'post_type', array( 'post', 'article' ) );\n    }\n    return $query;\n}<\/pre><p>In this function, <strong>$query-&gt;set()<\/strong> takes two parameters &ndash; the modified property and an array defining its value. In our case, the modified property is <strong>post_type<\/strong>, while the arrays&rsquo; values are <strong>post <\/strong>and <strong>article<\/strong>.<\/p><p>The array includes &lsquo;<strong>post<\/strong>&rsquo; to show the default post type on the front of your website. Removing it will display only the custom posts.<\/p><p>The second parameter is &lsquo;<strong>article<\/strong>&rsquo;, which displays regular and all custom article posts on the front page.<\/p><p>To enable the code, paste it to your theme&rsquo;s <strong>functions.php <\/strong>or custom plugin&rsquo;s file. We will show you how to paste it into the plugin:<\/p><ol class=\"wp-block-list\">\n<li>Access your WordPress site files and go to your custom plugin&rsquo;s folder. Ours is in the <strong>\/public_html\/wp-content\/plugins\/custom-post-type<\/strong>.<\/li>\n\n\n\n<li>Open the <strong>.php<\/strong> file. Then, copy and paste the code at the bottom.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/The-code-for-displaying-custom-post-type-in-the-plugin_s-file.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"551\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-code-for-displaying-custom-post-type-in-the-plugin_s-file.png\/w=1024,h=1024,fit=scale-down\" alt=\"The code for displaying custom post type in the plugin's file\n\" class=\"wp-image-73120\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-code-for-displaying-custom-post-type-in-the-plugin_s-file.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-code-for-displaying-custom-post-type-in-the-plugin_s-file.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-code-for-displaying-custom-post-type-in-the-plugin_s-file.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-code-for-displaying-custom-post-type-in-the-plugin_s-file.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"3\">\n<li>Click the <strong>disk<\/strong> <strong>icon<\/strong> on the top right to save your changes.<\/li>\n<\/ol><p>The default and custom post types should be available on the front of your WordPress website.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-add-and-display-wordpress-custom-field\">How to Add and Display WordPress Custom Field<\/h2><p>After creating a new custom post type, you may need to add a custom field to give your content more details.<\/p><p>For this task, you can use WordPress&rsquo;s built-in custom field or a plugin. Since every method has its pros and cons, we&rsquo;ll explain both to help you decide which suits you better.<\/p><h3 class=\"wp-block-heading\" id=\"h-using-wordpress-default-custom-field\">Using WordPress Default Custom Field<\/h3><p>WordPress provides us with a built-in tool to add a custom field. Since it is hidden by default, activate it by going to the <strong>Post Editor <\/strong>&rarr; <strong>Screen Option<\/strong>.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Screen-Option-menu-in-WordPress-post-edit-screen.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"349\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Screen-Option-menu-in-WordPress-post-edit-screen.png\/w=1024,h=1024,fit=scale-down\" alt=\"The Screen Option menu in WordPress post edit screen\n\" class=\"wp-image-73121\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Screen-Option-menu-in-WordPress-post-edit-screen.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Screen-Option-menu-in-WordPress-post-edit-screen.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Screen-Option-menu-in-WordPress-post-edit-screen.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Screen-Option-menu-in-WordPress-post-edit-screen.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-Screen-Option-menu-in-WordPress-post-edit-screen.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><p>Once activated, you will see the custom field section at the bottom of the WordPress edit screen. Enter the name and value, and click the <strong>Add Custom Field<\/strong> button.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/WordPress_s-default-custom-field.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"428\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/WordPress_s-default-custom-field.png\/w=1024,h=1024,fit=scale-down\" alt=\"WordPress's default custom field\n\" class=\"wp-image-73122\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/WordPress_s-default-custom-field.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/WordPress_s-default-custom-field.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/WordPress_s-default-custom-field.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/WordPress_s-default-custom-field.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/WordPress_s-default-custom-field.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><p>However, custom fields won&rsquo;t display on your page&rsquo;s front end by default. To enable them, insert <strong>the_meta()<\/strong> or <strong>echo get_post_meta()<\/strong> function into your active theme&rsquo;s file.<\/p><p>Use <strong>the_meta()<\/strong> to display all custom fields on a post. To display a specific custom field, use the <strong>echo get_post_meta( $post-&gt;ID, &lsquo;key&rsquo;, TRUE)<\/strong>. Replace the <strong>key<\/strong> value with your custom field name.<\/p><p>Since there are two post types, you can edit <strong>single.php<\/strong> or <strong>single-article.php<\/strong>. It depends on where you want to display the custom field.<\/p><p>Suppose you want to add an <strong>Author<\/strong> custom field for the custom article-type posts. In that case, enter one of the function codes in the <strong>single-article.php <\/strong>file. Here are the steps:<\/p><ol class=\"wp-block-list\">\n<li>From your WordPress Dashboard, head to <strong>Appearance <\/strong>&rarr; <strong>Theme Editor<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Theme-file-editor-menu-in-the-WordPress-sidebar.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"604\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Theme-file-editor-menu-in-the-WordPress-sidebar.png\/w=1024,h=1024,fit=scale-down\" alt=\"Theme file editor menu in the WordPress sidebar\n\" class=\"wp-image-73123\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Theme-file-editor-menu-in-the-WordPress-sidebar.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Theme-file-editor-menu-in-the-WordPress-sidebar.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Theme-file-editor-menu-in-the-WordPress-sidebar.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Theme-file-editor-menu-in-the-WordPress-sidebar.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Theme-file-editor-menu-in-the-WordPress-sidebar.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"2\">\n<li>From the <strong>Theme FIles <\/strong>menu on the right side of your screen, select <strong>singe-article.php<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/single-article.php-in-the-WordPress-theme-file-editor-screen.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"762\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/single-article.php-in-the-WordPress-theme-file-editor-screen.png\/w=1024,h=1024,fit=scale-down\" alt=\"single-article.php in the WordPress theme file editor screen\" class=\"wp-image-73124\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/single-article.php-in-the-WordPress-theme-file-editor-screen.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/single-article.php-in-the-WordPress-theme-file-editor-screen.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/single-article.php-in-the-WordPress-theme-file-editor-screen.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/single-article.php-in-the-WordPress-theme-file-editor-screen.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/single-article.php-in-the-WordPress-theme-file-editor-screen.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"3\">\n<li>Locate the <a href=\"https:\/\/codex.wordpress.org\/the_loop\">WordPress&rsquo; The Loop<\/a> and find this line:<\/li>\n<\/ol><pre class=\"wp-block-preformatted\">get_template_part( 'template-parts\/post\/content', get_post_format() );<\/pre><ol class=\"wp-block-list\" start=\"4\">\n<li>Paste one of the function codes under the line.<\/li>\n\n\n\n<li>Click <strong>Update File<\/strong>.<\/li>\n<\/ol><p>Your WordPress website will now show the <strong>Author<\/strong> custom field below the post.<\/p><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/An-author-custom-field-displays-under-a-post.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"840\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/An-author-custom-field-displays-under-a-post.png\/w=1024,h=1024,fit=scale-down\" alt=\"An author custom field displayed under a post\n\" class=\"wp-image-73125\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/An-author-custom-field-displays-under-a-post.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/An-author-custom-field-displays-under-a-post.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/An-author-custom-field-displays-under-a-post.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/An-author-custom-field-displays-under-a-post.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/An-author-custom-field-displays-under-a-post.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><h3 class=\"wp-block-heading\" id=\"h-limiting-custom-fields-to-a-specific-post-type-via-a-plugin\">Limiting Custom Fields to a Specific Post Type via a Plugin<\/h3><p>Unfortunately, you can&rsquo;t use WordPress&rsquo;s built-in tool to add a custom field for a specific post type. This default tool automatically adds a new custom field for all post types.<\/p><p>Instead, use the <a href=\"https:\/\/wordpress.org\/plugins\/advanced-custom-fields\/\">Advanced Custom Fields<\/a> plugin. It limits certain custom fields, making them selectable only on a chosen post type.<\/p><p><div class=\"announcement-block announcement-block--important\">\n            <span class=\"announcement-block__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path fill-rule=\"evenodd\" clip-rule=\"evenodd\"\n                          d=\"M12 22.5C17.799 22.5 22.5 17.799 22.5 12C22.5 6.20101 17.799 1.5 12 1.5C6.20101 1.5 1.5 6.20101 1.5 12C1.5 17.799 6.20101 22.5 12 22.5ZM13.637 7.65198C13.637 6.74791 12.9041 6.01501 12 6.01501C11.0959 6.01501 10.363 6.74791 10.363 7.65198C10.5335 9.53749 10.875 13.383 10.875 13.383C10.875 14.0043 11.3787 14.508 12 14.508C12.6213 14.508 13.125 14.0043 13.125 13.383V13.38L13.637 7.65198ZM11.9927 15.714C11.3714 15.714 10.8677 16.2177 10.8677 16.839C10.8677 17.4603 11.3714 17.964 11.9927 17.964H12.0073C12.6286 17.964 13.1323 17.4603 13.1323 16.839C13.1323 16.2177 12.6286 15.714 12.0073 15.714H11.9927Z\"\n                          fill=\"#FEA419\"\/>\n                <\/svg>\n                Important\n            <\/span>\n            <p class=\"announcement-block__content\">\n                <strong>Important!<\/strong> After this plugin is enabled, you will no longer see the default WordPress custom field on your post editor.\n            <\/p><\/div>\n\n\n\n<\/p><p>After you activate the plugin, follow these steps to create and enable a custom field for a specific post type:<\/p><ol class=\"wp-block-list\">\n<li>Go to your WordPress sidebar, click <strong>Custom Fields <\/strong>&rarr; <strong>Add New<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/The-add-new-custom-field-option-in-the-WordPress-sidebar.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1460\" height=\"732\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-add-new-custom-field-option-in-the-WordPress-sidebar.png\/w=1024,h=1024,fit=scale-down\" alt=\"The add new custom field option in the WordPress sidebar\" class=\"wp-image-73126\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-add-new-custom-field-option-in-the-WordPress-sidebar.png\/w=1460,fit=scale-down 1460w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-add-new-custom-field-option-in-the-WordPress-sidebar.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-add-new-custom-field-option-in-the-WordPress-sidebar.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-add-new-custom-field-option-in-the-WordPress-sidebar.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/The-add-new-custom-field-option-in-the-WordPress-sidebar.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1460px) 100vw, 1460px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"2\">\n<li>Enter the <strong>New Field Group <\/strong>name.<\/li>\n\n\n\n<li>Fill in the following details for your new custom field:<\/li>\n<\/ol><ul class=\"wp-block-list\">\n<li><strong>Field Label<\/strong> &ndash; the name of your custom field that will be displayed on the edit page.<\/li>\n\n\n\n<li><strong>Field Name<\/strong> &ndash; the ID of your custom field that will be used to display on your theme.<\/li>\n\n\n\n<li><strong>Field Type<\/strong> &ndash; choose between text, checkbox, URL, etc., based on your needs.<\/li>\n<\/ul><ol class=\"wp-block-list\" start=\"4\">\n<li>Once you&rsquo;re done, hit <strong>Close Field<\/strong>.<\/li>\n\n\n\n<li>Scroll down to the <strong>Settings <\/strong>section and select the <strong>Location Rules <\/strong>tab.<\/li>\n\n\n\n<li>Fill the <strong>Show this field if <\/strong>columns<strong> <\/strong>to define the custom field&rsquo;s visibility condition. For example, to make it selectable on a <strong>Custom Article <\/strong>post type, choose <strong>Post Type <\/strong>&rarr; <strong>is equal to<\/strong> &rarr; <strong>Custom Article<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><a href=\"\/ng\/tutorials\/wp-content\/uploads\/sites\/2\/2020\/02\/Advanced-Custom-Field-plugin_s-location-rules-settings.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"502\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Advanced-Custom-Field-plugin_s-location-rules-settings.png\/w=1024,h=1024,fit=scale-down\" alt=\"Advanced Custom Field plugin's location rules settings\" class=\"wp-image-73127\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Advanced-Custom-Field-plugin_s-location-rules-settings.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Advanced-Custom-Field-plugin_s-location-rules-settings.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Advanced-Custom-Field-plugin_s-location-rules-settings.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2020\/02\/Advanced-Custom-Field-plugin_s-location-rules-settings.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><\/div><ol class=\"wp-block-list\" start=\"7\">\n<li>Click the <strong>Save Changes <\/strong>button.<\/li>\n<\/ol><p>Since you create this field via a plugin, you must use its functions to display the custom field. The steps to insert the function are similar to adding a default custom field, but enter <strong>the_post( &lsquo;key&rsquo; ); <\/strong>function instead.<\/p><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-wordpress-hosting\" href=\"\/ng\/wordpress-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"600\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=1024,h=1024,fit=scale-down\" alt=\"\" class=\"wp-image-111781\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=2048,fit=scale-down 2048w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=768,fit=scale-down 768w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2024\/06\/New-WP_in-text-banner.png\/w=1536,fit=scale-down 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/a><\/figure><h2 class=\"wp-block-heading\" id=\"h-conclusion\">Conclusion<\/h2><p>Custom post type in WordPress allows users to organize their website content into different categories. However, the default post types may not be enough for a large website with diverse content.<\/p><p>In that case, you can create a custom post type in WordPress by building site-specific plugins. Here&rsquo;s the recap of the steps:<\/p><ol class=\"wp-block-list\">\n<li>Write the plugin code in a text editor and save it as <strong>.php<\/strong>.<\/li>\n\n\n\n<li>Create a custom post type folder in your site&rsquo;s plugins directory.<\/li>\n\n\n\n<li>Paste the file into the new folder.<\/li>\n\n\n\n<li>Go to your <strong>WordPress admin dashboard<\/strong> &rarr; <strong>Plugins<\/strong> &rarr; <strong>Installed Plugins<\/strong><\/li>\n\n\n\n<li>Find the custom post type plugin and click <strong>Activate<\/strong>.<\/li>\n<\/ol><p>Your custom post type also has plenty of customization options. For instance, you can customize the editing screen, add meta boxes, edit the post type&rsquo;s visibility, and enable WordPress&rsquo;s built-in features.<\/p><p>This vast customizability lets you create a post type that specifically caters to your content. It helps you organize your WordPress website faster and more efficiently.<\/p><p>        <div class=\"protip\">\n            <div class=\"protip__heading\">\n                <svg width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"none\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\">\n                    <path d=\"M1.49234 23.5024C1.23229 23.5024 0.972242 23.4024 0.782206 23.2123C0.562165 22.9923 0.452144 22.6822 0.502153 22.3722C0.562165 21.9221 1.14227 17.9113 3.00262 16.351C3.63274 15.8209 4.43289 15.5509 5.26305 15.5609C6.09321 15.5909 6.87335 15.9109 7.47347 16.4911C8.6937 17.6913 8.76371 19.6717 7.6435 20.9919C6.0832 22.8523 2.08245 23.4324 1.63237 23.4924C1.59236 23.4924 1.54235 23.4924 1.50234 23.4924L1.49234 23.5024ZM5.16303 17.5613C4.84297 17.5613 4.53291 17.6713 4.29287 17.8813C3.60274 18.4614 3.07264 19.9317 2.75258 21.242C4.06282 20.9219 5.5331 20.3918 6.11321 19.7017C6.55329 19.1716 6.54329 18.3814 6.0832 17.9213C5.85316 17.7013 5.5431 17.5713 5.20304 17.5613C5.19304 17.5613 5.17303 17.5613 5.16303 17.5613ZM11.7243 21.8821C11.4942 21.8821 11.2642 21.8021 11.0841 21.652C10.8541 21.462 10.7241 21.1819 10.7241 20.8819V15.9109L8.08358 13.2705H3.11264C2.81259 13.2705 2.53254 13.1404 2.3425 12.9104C2.15246 12.6803 2.07245 12.3803 2.12246 12.0902C2.19247 11.7102 2.84259 8.36953 4.70294 7.12929C6.33325 6.04909 8.96375 6.49918 10.244 6.80923C11.5442 4.96889 13.2546 3.4286 15.2349 2.33839C17.4553 1.11816 19.9858 0.518051 22.4963 0.498047C23.0464 0.498047 23.4865 0.948132 23.4865 1.49824C23.4865 5.0389 22.3763 9.97983 17.1753 13.7605C17.4853 15.0408 17.9354 17.6613 16.8552 19.2816C15.615 21.1419 12.2744 21.7921 11.8943 21.8621C11.8343 21.8721 11.7743 21.8821 11.7143 21.8821H11.7243ZM12.7245 16.181V19.6016C13.7146 19.2916 14.7948 18.7915 15.2049 18.1814C15.675 17.4812 15.605 16.091 15.385 14.9008C14.5248 15.3808 13.6346 15.8109 12.7245 16.181ZM9.66388 12.0302L11.9643 14.3307C13.1845 13.8306 14.3648 13.2204 15.485 12.5103C19.9358 9.51974 21.2361 5.60901 21.4561 2.53843C19.6157 2.67846 17.8254 3.20856 16.2051 4.09872C14.2847 5.14892 12.6544 6.68921 11.4942 8.54956C10.7841 9.65977 10.174 10.82 9.66388 12.0302ZM4.39289 11.2701H7.81353C8.1936 10.3599 8.63368 9.46974 9.11377 8.60957C7.92355 8.38953 6.51329 8.31952 5.81315 8.78961C5.19304 9.19968 4.70294 10.3099 4.39289 11.2701Z\" fill=\"#673DE6\"\/>\n                <\/svg>\n                <p class=\"protip__title\">\n                    Learn Other Expert WordPress Techniques                <\/p>\n            <\/div>\n            <p class=\"protip__content\"><br>\n<a href=\"\/ng\/tutorials\/wordpress-custom-css\/\">How to Add Custom CSS to WordPress<\/a><br>\n<a href=\"\/ng\/tutorials\/wordpress-salts\/\">All About WordPress Salts<\/a><br>\n<a href=\"\/ng\/tutorials\/how-to-create-custom-widget-in-wordpress%20\/\">How to Create WordPress Custom Widgets<\/a><br>\n<a href=\"\/ng\/tutorials\/what-are-wordpress-hooks\/\">WordPress Hooks Guide<\/a><br>\n<a href=\"\/ng\/tutorials\/wordpress-post-template\/\">How to Create a Custom Post Template in WordPress<\/a><br>\n<a href=\"\/ng\/tutorials\/how-to-use-xampp-wordpress\/%20\/\">How to Use XAMPP to Set Up a Local WordPress Site<\/a><br>\n<a href=\"\/ng\/tutorials\/wordpress\/how-to-add-php-code-to-wordpress-post-or-page\/\">How to Add PHP Code to WordPress<\/a><br>\n<a href=\"\/ng\/tutorials\/how-to-duplicate-wordpress-page-or-post\/\">How to Duplicate Pages in WordPress<\/a><br>\n<a href=\"\/ng\/tutorials\/wordpress-get-post-meta\/\">How to Display Custom Field Metadata Using WordPress get_post_meta Function<\/a><\/p>\n                    <\/div>\n        \n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-wordpress-custom-post-type-faq\">WordPress Custom Post Type FAQ<\/h2><p>This section will answer three of the most common questions regarding WordPress&rsquo;s custom post type. However, if you have further questions, leave them in the comment action below.<\/p><div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1671537075069\"><h3 class=\"schema-faq-question\">What&rsquo;s the Difference Between a Post and a Custom Post Type?<\/h3> <p class=\"schema-faq-answer\">In WordPress, a<strong> post <\/strong>may refer to a single piece of content. It may also refer to a <a href=\"https:\/\/wordpress.org\/support\/article\/post-types\/\">post type<\/a>, similar to pages, attachments, revisions, and others.&nbsp;<br><br>Meanwhile, a<strong> custom post type <\/strong>is a content category that users make themselves.&nbsp;<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1671537092687\"><h3 class=\"schema-faq-question\">&#8203;&#8203;What Can You Change in the WordPress Custom Post Type?<\/h3> <p class=\"schema-faq-answer\">You can change its location in the admin area, searchability, and additional features like excerpts, <a href=\"\/ng\/tutorials\/wordpress-post-formats\/\">post formats<\/a>, and trackbacks.&nbsp;<br><br>Moreover, WordPress also allows you to modify the edit post screen and add custom fields to include more information in your content. For instance, you can display the post&rsquo;s author or reading time.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1671537112837\"><h3 class=\"schema-faq-question\">Is It Possible to Get a Custom Post Type ID?<\/h3> <p class=\"schema-faq-answer\">Yes. To see a <a href=\"\/ng\/tutorials\/wordpress-post-id\/\">WordPress post ID<\/a>, hover over the content&rsquo;s title and see the UR at the bottom left corner. It is the number between the &ldquo;<strong>post=<\/strong>&rdquo; and &ldquo;<strong>&amp;<\/strong>&rdquo; parameters.You can also get a custom post type unique ID by its title using the <strong>get_page_by_title () <\/strong>command. Alternatively, retrieve it using slug the <strong>get_page_by_path () <\/strong>command.<\/p> <\/div> <\/div>\n","protected":false},"excerpt":{"rendered":"<p>WordPress has multiple post types to help you organize your website&rsquo;s content. You can easily create a chronological blog or display static pages with them. However, the built-in post types may not be sufficient for large websites with diverse content. In that case, you need to create your own post type. This article will explain [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/wordpress-custom-post-types\/\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":337,"featured_media":144904,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to Create and Customize a WordPress Custom Post Type","rank_math_description":"Check out this article to learn how to use code and a plugin to create a WordPress custom post type, customize and display it on the website.","rank_math_focus_keyword":"wordpress custom post type","footnotes":""},"categories":[22637],"tags":[],"class_list":["post-7044","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/wordpress-custom-post-types","default":0},{"locale":"pt-BR","link":"https:\/\/www.hostinger.com\/br\/tutoriais\/como-criar-custom-post-types-wordpress","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/comment-creer-custom-post-type-wordpress","default":0},{"locale":"es-ES","link":"https:\/\/www.hostinger.com\/es\/tutoriales\/custom-post-types-wordpress","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-membuat-custom-post-types","default":0},{"locale":"en-GB","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/wordpress-custom-post-types","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/wordpress-custom-post-types","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/wordpress-custom-post-types","default":0},{"locale":"es-MX","link":"https:\/\/www.hostinger.com\/mx\/tutoriales\/agregar-meta-descripcion-wordpress-5","default":0},{"locale":"es-CO","link":"https:\/\/www.hostinger.com\/co\/tutoriales\/agregar-meta-descripcion-wordpress-5","default":0},{"locale":"es-AR","link":"https:\/\/www.hostinger.com\/ar\/tutoriales\/custom-post-types-wordpress","default":0},{"locale":"pt-PT","link":"https:\/\/www.hostinger.com\/pt\/tutoriais\/como-criar-custom-post-types-wordpress","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/wordpress-custom-post-types","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/wordpress-custom-post-types","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/wordpress-custom-post-types","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/wordpress-custom-post-types","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/7044","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/337"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=7044"}],"version-history":[{"count":87,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/7044\/revisions"}],"predecessor-version":[{"id":144903,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/7044\/revisions\/144903"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media\/144904"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=7044"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=7044"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=7044"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}