The smart way to disable your sidebar

If you find yourself making a new WordPress template for pages that are identical to others on your site but just don’t have a sidebar, consider this technique instead which lets you turn the sidebar off selectively on a page by page basis.

Add this to functions.php

index.php, page.php … etc.

Next find the file that has the sidebar in it. If you want this to work on all blog posts, it’s probably single.php, or if you add it to index.php and/or page.php it’ll work on other types of pages. Once you find your sidebar you need to put a bit of code before it and a bit of code after it. In the beginning bit looks to see if the custom field is set on your page, the second bit is just the end of the ‘if’ statement

what it does

It checks to see if you have a custom field set in your post to disable the sidebar and if you do it turns off the sidebar

how to use it

Just make a new custom field for your page called disableSidebar and set it to true. That’s it.

Topics covered:
Enable Javascript