Unlock your potential with a Pro Membership
Here is where you propel your career forward. Come join us today. Learn more.
Strategy 4: Reusable Function
Lab: Remove the Genesis Site Footer on Home Page
Video Runtime: 11:18
The fourth strategy is to encapsulate the functionality and abstract it away to a reusable function within your child theme. Let’s do this together.
While you could add this function to your child theme’s functions.php
file, it’s better to build your theme’s in a modular format.
Best Practice – Modular Approach
Using a modular approach, you will create a folder in the theme’s lib
folder and call it structure
. Then in the {child theme}/lib/structure
folder, create a new file called footer.php
. Here is the code that removes the site footer for each of the pages that you specify:
-
Namespace code example
-
Prefixed code example
You’ll need to load this new file into your theme by adding the following line of code to your theme’s function.php
file:
include_once( __DIR__ . '/lib/structure/footer.php' );
I want to put it in my functions.php
Okay, if you prefer to put it into your functions.php
file instead of using the modular approach, here is the code for you. Just change the prefix to what you are using.
-
Prefixed code example
When to Use this Approach?
You use this approach when you will have multiple pages where you want to remove the site footer. For example, let’s say you want to remove the site footer on the Posts’ Page, Front Page, About, Contact, Archives, etc. Then you can use this strategy.
Otherwise, it’s a better approach to use strategy 2 or 3. Why? Because this function gets called for every single web page on your website. Every single one. It’s always going to call this function and then check if it’s the right page. It’s a little slower than strategy 2 and 3. It’s also a little more confusing.
There’s a time to code and …. yup, that sums it up.
Episodes
Total Lab Runtime: 00:33:41
- 1 Lab Introductionfree 02:35
- 2 Strategy 1: Hide it with CSSfree 06:17
- 3 Strategy 2: Remove the Individual Genesis Footer Actionspro 05:30
- 4 Strategy 3: Remove All Genesis Footer Actionspro 03:09
- 5 Strategy 4: Reusable Functionpro 11:18
- 6 Which One to Use?pro 04:52