How it works...
In this recipe, we wanted to show user profile data in the frontend using a custom URL structure, instead of using a shortcode inside posts or pages. We started the process by using a callback function called wpccp_chapter7_manage_user_routes on the init action. Inside this function, we used the add_rewrite_rule function to define a custom route to load the user profile template. This function is part of the WordPress Rewrite API where a given URL is transformed into a set of query variables. These query variables allow us to separate one request from another and load the correct custom template instead of using built-in theme templates.
The first parameter of the add_rewrite_rule function defines the regular expression to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access