Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In the previous movie, we created three basic custom post types. But as you saw, when we went to WordPress Admin, when creating a new post under them, the text displayed inside WordPress still calls all of them just Post. Though, this doesn't look like much right away. It's a bit sloppy and it can also lead to confusion. After all, when you click Add New under Recipes, why does it say create new post? Fortunately, we can fix out this with a few more lines of code in our function. Each of the custom post type definition functions can have a variable called labels.
This is where we put all the labels for a custom post type. This variable can take an array of labels. So we are going to create a new separate array and then call it from within the function itself. If you go to your code-snippets, you see here under 03_03, there's an example of a new array for recipes. It starts with recipe_labels and then it goes down to this end bracket. So, if you copy this, go into your posttypes, scroll to the top, and find your arguments for the register_post_type, and then paste in the new array directly above it, we now have an array we can call from inside a basic function to display all the information about the content.
If we look at this array, you will see we have more specific definitions about all the text. We have the name of the posttype, Recipes, we have the singular_name Recipe, and these correspond to the previous label and singular_label. We also have the text for all_ items, so it says All Recipes. We have add_new, Add new recipe, we have edit_item, we have new_item. This stuff just makes it clear inside WordPress Admin what is going on when you are working for the recipes.
So how do we activate this array? Well first, we should take out this singular_label, because we already have a repeated up here, so I will take that whole line out, and then instead of saying label, we will say labels and call the array. The array is called $recipe_ labels, so that's what you put in. And when we now save the posttypes.php file, and go back to WordPress admin, and reload, you will see a subtle change.
We now have all recipes under Recipes, Add new recipe, and in the actual single view, you see it says Add new recipe rather than saying Add New Post. We can do the exact same thing for Photos and Videos, just because it's a lot of code, I've created it for you, so what you can do if you don't want to do this manually is simply go to the code -snippets, find it where it says Full code for posttypes.php and copy all the code all the way down to the end of the php delimiter.
Copy this, go back to the code editor, under posttypes.php, delete everything and just paste in this new content. When I save it, reload WordPress Admin, we now have all the new post types and as you can see when we open them, under Photos we have All Photos, Add new photo, under Videos we have All Videos, and when we select them, it will say Add new video here as well. Setting up the proper labels for a custom post type not only makes the post type easier to use, but also adds a new layer of professionalism to it.
And as you've seen, it's easy to do, which is always a bonus.
Get unlimited access to all courses for just $25/month.Become a member
119 Video lessons · 50936 Viewers
117 Video lessons · 38663 Viewers
113 Video lessons · 81567 Viewers
65 Video lessons · 11583 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.