Caleb
Caleb

Reputation: 825

Completely changing custom post type through child theme

I have a Wordpress theme that has a custom post type (called "menu"). I want to change the name, slug, labels, etc to "Recipes" through a child theme. I can easily change the labels, but if I change the slug, it will mess up all the templates, custom functions, etc that are related to the "menu" custom post type. Is there a way for me to rewrite any functions/templates referencing the "menu" CPT to point to the "recipes" CPT?

Thanks!

Upvotes: 2

Views: 879

Answers (1)

Pieter Goosen
Pieter Goosen

Reputation: 9941

In my personal opinion, the best route here would be to simply register a new post type. If you change the custom post type name, you have to change every instance where that name is used to the new name, and what if there are functions in the parent theme that can't be overwritten or are not filterable.

Remember, custom post types should be in plugin, not in a theme.

Here is my idea. Do the following in a custom plugin:

  • Create a custom post type called recipes. If you need to change posts that are already in the other post type, simply download a plugin that can change a post's post type to another post type

  • Copy all the functions to to your plugin that needs to be changed. Rename them and modify as needed.

This will ensure that, when you change themes, you will not loose your post type

Upvotes: 1

Related Questions