With all code, you first need to initialize it. Initialization prepares a codebase and environment for operation. It includes tasks such as loading files, constants, and setting default states.
Pop Quiz Time
After you watch the episode, answer these questions.
In your child theme, do you have to 'start the engine' and load the Genesis init.php file?
No. WordPress loads both the child and parent (meaning Genesis) theme’s
Where does that happen? Go to the root of your website and open the
wp-settings.phpfile. Scroll down to about line 421. You’ll see how it loads both
functions.phpfiles, i.e. first the child theme and then the parent. Remember this as it’s important!
Why do StudioPress child themes 'start the engine' first in their functions.php files?
Look at what’s in their child theme. They are unregistering certain default features using
remove_filter. Then they are using functions that are from the Genesis framework, such as
Okay, so why is this code typically the first line in their child themes’
<?php //* Start the engine include_once( get_template_directory() . '/lib/init.php' );
Think about it.
In order to remove an action or filter, first, that callback has to be registered. You can unregister something that has already been loaded into memory and registered. Not sure what the heck I’m talking about? Go watch the What is the Event Management System? episode.
For the functions, each has to be loaded into memory before you can use it. Think about that. If you want to use
genesis_unregister_layout(), PHP needs to be called to call that function and run it. It can’t do that until the file is loaded and it’s loaded into memory.
Therefore, the way StudioPress builds their themes is the child theme first loads the Genesis framework before it does anything else. That’s one strategy.
But you don’t have to do it that way. In the Let’s Build a Custom Developer’s Genesis Starter Theme series, I show you how to load the framework last.
Does all of that make sense to you? If no and you’re a Pro member, head over to the Pro Forums and ask me to clarify it for you.
Your functions are bloated. Put them on a diet. Think "skinny" and "as few lines as possible."
Total Lab Runtime: 02:47:43
- 1 Lab Introductionfree 10:07
- 2 The Why of the Genesis Frameworkfree 09:26
- 3 Web Page Sequencefree 07:33
- 4 Web Page Sequence - in the Codefree 14:54
- 5 The Intent of HTML and its Markupfree 08:45
- 6 The Intent of the Themefree 11:17
- 7 WordPress Event (Plugin API) Refresherfree 12:19
- 8 Visual Hook Guide and the HTML - Headerfree 10:10
- 9 Visual Hook Guide and the HTML - Contentfree 10:01
- 10 Visual Hook Guide and the HTML - Sidebarfree 09:22
- 11 Visual Hook Guide and the HTML - Footerfree 08:34
- 12 File Architecturefree 12:32
- 13 Codebase Architecturefree 10:03
- 14 Event Naming Conventionfree 08:50
- 15 Initialize & Setup Overviewfree 07:50
- 16 Initializing Genesisfree 06:09
- 17 Setting Up Genesisfree 08:15
- 18 Wrap it Upfree 01:36