WordPress is a wonderful CMS (Content Management System), currently a large percentage of websites are built on this platform. Its easy handling and low learning curve make users opt for this platform. But the question always arises of how to get the most out of WordPress, since this post will be directed to an important part of this technology, we will talk about CPT (Custom Post Type).
What are Custom Post Type?
Custom Post Type in WordPress are just that, post types. We know that WordPress defines two important types of posts by default, post and page, and these are used to create posts in our blog, or to create the pages of our website. We can define a set of posts for our blog and they will be defined under certain categories that will classify the content.
The magic question would be this, what is the use of this? Well, it is very easy, the truth when WordPress arose was thinking to create blogs, that is, having a set of entries under a certain number of categories. But today this technology is used for any type of project, such as: e-commerce, a book website and even more. As they manage to create all types of content, it is just as simple, with the Custom Post Type. If we want our website to have a Portfolio, showing our work, we only have to create a Custom Post Type for it.
¿Comó crear un Custom Post Type en WordPress?
There are quick solutions like plugins that perform this task, for example Custom Post Type UI . But I always defend the idea of not using plugins for everything, that is why I leave you with some steps on how to create custom post type manually.
Always remember that the code must be in the functions.php file in your theme or the child theme (or inside of a custom plugin).
The first step is to define a function, in my case it will be called wr_portfolio_cpt, to avoid collisions with other code it is always important to define the names of the functions with prefixes or suffixes, my theme is called Web Ready so my prefix is wr, and the CPT suffix referring to what the function defines, in this case Custom Post Type.
This function defines two variables ($labels, $args) and an internal function (register_post_type).
The variable $labels is an array that defines some properties that are used to define labels such as: the name with which the CPT will appear in the right menu in WordPress and other labels that you will see at the moment that you can customize.
The variable $arg is used as the second parameter of the function register_post_type(), it is like $ labels an array, and it already defines properties that are more functional like: the positions in the left menu in WordPress, or if you want to define a icon and even the elements you want this CPT to have.
Define the hook that you created in a new CPT called portfolio.
Custom Post Types are one of the key pieces of the WordPress core. Turn this CMS into a powerful tool for creating websites of all dimensions. Its use provides this platform with enormous versatility, since it does not limit it only to blogs, but to all types of projects. Currently this functionality makes WordPress have more followers and makes it the technology to follow right now. Please any questions write us or just leave a comment below.