Skip to content

Filter: Add/remove sidebars

The md_filter_has_sidebar filter allows you to bypass the MD sidebar controls and conditionally add/remove the sidebar on any page.

By loading the filter through template_redirect we can use a WordPress conditional tag to ensure the filter only fires on the page(s) we want it to.

When using the filter you only need to choose the conditions and return a value of true or false to add/remove the sidebar from the given page. This would usually be done by creating a function with either return value, but we can instead use the native WordPress return functions to save us some code:

  • __return_true()
  • __return_false()

This code snippet ADDS the sidebar to author pages and REMOVES the sidebar from a specific post category page. You can repeat this action as many times as you need.

Note: loading this filter without any kind of conditional tag will affect the behavior of your sidebar sitewide so be careful to only use this filter in the right context.

Alex Mangini

Hi, I'm Alex! I started writing about web design and blogging at 13 years old, which turned into client work, which led to building my own software. 15 years later I'm still at it, and Marketers Delight is the epitome of my philosophy for building on the web.