There are a couple of other things that I want to do with this custom template with custom sidebar that we just created in Genesis. This works just fine. In fact, instead of this body class let’s add the ‘projects’ body class to that filter.
Why You Might Want To Force a Specific Layout
The next thing I want to do is to force this template to have a specific layout in Genesis. If you are the designer and you’ve designed these pages to look a specific way, I don’t want the client inadvertently choose sidebar_content_sidebar or sidebar_sidebar_content or something similar that ends up making the page look wrong.
In other words, I don’t want them to have a choice as to the layout of this page. I want to force that layout. In order for us to do that we need to use a filter and that filter is called the genesis_site_layout filter.
So what we’re going to do is create a function. Let’s say byob_project_template_layout. Then down here we’re going to say add_filter the name of this filter is ‘genesis_site_layout. Actually I’m sorry, I don’t need the function.
How to Call an Existing Genesis Filter
We don’t need a function in order to do this because what we’re doing is hooking in to an existing Genesis function. Genesis has a set of function that are designed for you to call to the filters.
You don’t have to create your own function to do this. You can call an existing Genesis filter and so the way we do that it is ‘genesis_return_content_sidebar’. Note the double underscores so it’s genesis_return and then content_sidebar as the style.
6 Different Genesis Layouts
Just so you can see that in action. I’m going to come over here to the Genesis folder and find that. It’s in layout.php. Here’s what you have.
These are the 6 layouts that you can choose from when you are picking a layout of the page. And all we have to do is call the function that returns the style that we want.
Calling One of the Layouts
We want content sidebar so we’re going to return genesis_return_content_sidebar, that’s what we’re doing here. We’re calling that function with this. It’s actually quite simple.
Then let’s upload it and refresh this. Oh, I must have typed something incorrectly. Genesis body class must be the type array. Pardon me, what did I do wrong with the body class. Let’s see, we’ve removed the sidebar, we’ve added our own custom sidebar, we’ve got our custom body classes, it is an array.
No, that was a mistake. This is actually the byob_projects_body_class and then that’s the name of the body class and we are returning ‘projects’. So you’ve got byob_projects_body_class($classes) $classes = ‘projects’, return $classes. So that’s where the problem was.
Let’s inspect the element and look at our body class. Now we have projects right there, you can see and we’ve still got our sidebar the way we want it. But if we come over to the page we’ve got our Projects Template.
And you can’t change the layout. Let’s pick “sidebar_sidebar” for the layout and view the page. It didn’t do it because it doesn’t matter what you choose because we’ve already said to override whatever choices there are here and give us the content_sidebar layout.
For designers and developers, when you’re working on a site for a client it can be a total pain in the butt for them to say, “I wonder what would happen if I click this button” or if their VA clicks the wrong button or changes the default by accident.
Well, this gives you control over your design and allows you to prevent that kind of thing from happening and thus prevent having the service call or tech support or something like that. So this can be a very useful function.