0
0
Wordpressframework~30 mins

Why content types matter in Wordpress - See It in Action

Choose your learning style9 modes available
Why Content Types Matter in WordPress
📖 Scenario: You are building a simple WordPress site for a local bakery. You want to organize the website content clearly so visitors can easily find information about products, events, and blog posts.
🎯 Goal: Learn how to create and use custom content types in WordPress to organize different kinds of information on your website.
📋 What You'll Learn
Create a custom post type called product for bakery items
Create a custom post type called event for bakery events
Add a configuration variable to set the public visibility of the post types
Register the custom post types using WordPress functions
💡 Why This Matters
🌍 Real World
Organizing content into custom post types helps websites show different kinds of information clearly, like products and events for a bakery.
💼 Career
Knowing how to create and manage custom post types is a key skill for WordPress developers building flexible, user-friendly websites.
Progress0 / 4 steps
1
Create the product custom post type
Write code to register a custom post type called product using the register_post_type function with a label of 'Products'.
Wordpress
Need a hint?

Use register_post_type with the first argument as 'product' and an array with labels and public keys.

2
Create the event custom post type
Add code to register a custom post type called event with a label of 'Events' and set a variable $is_public to true to control visibility.
Wordpress
Need a hint?

Create a variable $is_public set to true and use it in the public option when registering the event post type.

3
Use the visibility variable for both post types
Modify the register_post_type calls for both product and event to use the variable $is_public for the public option instead of hardcoded true.
Wordpress
Need a hint?

Set $is_public = true before both register_post_type calls and use 'public' => $is_public in both.

4
Complete the registration with init hook
Wrap the register_post_type calls inside a function called register_custom_post_types and hook it to WordPress init action using add_action('init', 'register_custom_post_types').
Wordpress
Need a hint?

Define a function register_custom_post_types that contains the post type registrations, then use add_action('init', 'register_custom_post_types') to run it.