Never use themes with CPTs – .com

You should never use themes that embed their own CPTs, because they will disappear when you change themes.

Custom Post Types

By default WordPress comes with “Posts” and “Pages”. But there is a functionality that allows us to create new types of content: The CPT.

Custom Post Types are new types of content that we can add to WordPress. For example, in my case I have: News, pages, podcasts, courses, tutorials and downloads.

CPTs can be added mainly in two ways:

  • through a theme
  • Through a plugin

Let’s take a look at both approaches and see why it’s such a bad idea for a theme to embed its own Custom Post Types.

Custom Post Type in a theme

We must avoid this method at all costs, since all those Custom Post Types that come with a theme will disappear when we deactivate it.

For example, when we activate the never recommended we realize that the CPT “Projects” has appeared out of nowhere in the control panel:

At first this may seem like a good thing, because you think “Ah, great, so I have everything in the theme, and I don’t need to install a plugin“. But the problem is precisely there! You must use a plugin!

Why? Imagine for a moment that you use Divi’s CPT. Everything seems to work great, and you are creating content day after day, year after year. Until one fine day, you decide to change the theme.

Sooner or later it will happen, believe me. There will be a day that for whatever reason, you will want a newer, more different, lighter theme (remember that)or simply for design reasons.

See also  461. Phrases to frame - .com

Do you know what will happen when you deactivate Divi and activate another theme? Indeed, this:

As you can see, “Everything that comes with a theme, leaves with the theme”. Obviously they have not been “deleted”, since they are still in the database, but recovering them now will be a problem, because It is not only about recovering the CPTs, but also all the custom fields (Custom Fields) that go with them. So, what can we do now?

This is what is called the “Lock-in” effect. In other words, you are “locked” in that theme. This is done by the theme developers so that you never abandon them, and remain tied to their themes, without having the option to change.

So where should those CPTs be defined? Easy! In plugins.

Custom Post Types in plugins

Unlike themes, all the code that comes in a plugin is maintained even if we change the theme.

For example, if we install the plugin, we will see that the following appears:

As you can see, the plugin has added a new content called “Portfolio”, with its categories and tags. Well then if we now change the theme, all that information is keptwith their respective custom fields.

So, theme developers who want to create features such as CPTs, what they should do is create a standalone plugin of its theme, that is complemented There are .

In this way we have a couple of very important advantages:

  • The user will only install the plugin if he needs that CPT. If not, why have all that code there? We gain in performance and speed!
  • If the user wants to use it and one day wants to change the theme, he does not lose any content, and everything continues to work correctly. We win in freedom!
See also  Migrate from Blogger to WordPress - .com

In fact, even the theme developer gains, as he can become known for both his themes and plugins. winning strategy. But there are still many who prefer to continue with the “lock-in” techniques to force users to continue with them.

That is why the WordPress.org theme review team does not accept themes in the official repository that have built-in CPTs. Because it is forbidden to put anything in a theme that will cause loss of content if the theme is left.

Summary and conclusion

CPTs with custom post types in WordPress. Some themes have it incorporated, but we must avoid them, because if one day we change the theme, we lose everything.

If we want to incorporate a new type of content, it is advisable to do it through a plugin for it, or .

And if you want to know more about WordPress, themes, plugins and development, take a look at the , more than 6047 videos at your disposal.

Loading Facebook Comments ...
Loading Disqus Comments ...