Devin Walker is a San Diego based entrepreneur, developer and designer.

Roots Theme: Display Sidebar Only for Certain Pages – Default Full Width

Posted on Jul 2, 2013 in Coding | 7 Comments

roots-themeThe Roots Theme for WordPress is awesome for creating great websites. I’ve built many of the sites in my portfolio on Roots and actually have one showcased in the Roots Gallery (Vets2Go). One situation I come across every so often is the need to reverse the logic of the Roots sidebar.

Roots Sidebar Explanation

Roots has conditional checks that if return true won’t show the sidebar. So, for instance take a look at the standard roots_display_sidebar function in config.php:

All the arguments below instruct the Roots core to not display the sidebar.php file. We want to reverse this logic so that the arguments will display the sidebar.

This is because our certain template needs to be full-width according to the design and functionality. No sidebar, unless I tell it so in the arguments above. Make sense?

Reverse the Sidebar Logic

If we take a gander into the Roots core we will find the Roots_Sidebar class in lib/sidebar.php:

Change public $display = true; to public $display = false; on line 17 in the file.

Next, change $this->display = false; to $this->display = true; on line 27.

Jump Back Into Config.php

Now that our logic is reversed we need to update our arguments to display the sidebar only on the pages we wish:

Now only pages that use template-sidebar.php will display our sidebar. This is exactly what I need for a full-width layout with some pages using a sidebar.

Anything Else?

Hopefully this solves your issue with the Roots sidebar full-width by default problem. Check out this thread over at the Roots Google group for more information into the source of this information. Thanks to Catherine Azzarello and iamboris for first uncovering the problem and solving it with this elegant solution.