Clarification on the Theme Sidebar documentation page

I’m new to Sage.

When reading, I don’t understand in which file I’m supposed to write the code block containing the sage_sidebar_on_special_page function, if I want such functionality.

This file determines which pages show the sidebar:

Does that mean that the code block that I mention in the original post is supposed to be added at the bottom of that file?

Line 36 of that file is where the code begins that determines which pages show sidebars. If you read the comments beneath that, it should become clear how to use it to show/hide the sidebar on various pages in various ways.

As far as I can tell from your question, that’s what you’re trying to achieve.

Sorry if I haven’t been clear: I’m trying to add a filter to force the display of the sidebar, as indicated in the “Filtering the Sidebar Class”.

From what I understand, the way to do it is to add the following code at the bottom of “config.php”:

add_filter('sage/display_sidebar', __NAMESPACE__ . '\\sage_sidebar_on_special_page');

    function sage_sidebar_on_special_page($sidebar) {
      if (is_page('special-page')) {
        return true;
      return $sidebar;

I’m probably not the best person to help building PHP functions, but I do know that Sage has a built in way of determining which pages show the sidebar, and the code to achieve this is in the file I linked to, starting on line 36.

By default Sage seems to enable the sidebar, allowing ways to disable it on special pages, but the function starting on line 36 of the linked file could easily be modified to reverse this.

Thanks for the answer, but I don’t really understand. I would need some code example of that filter inside one of the Sage pages. Which page? Where in the page?

In Sage, the file:


Contains the following instructions:

       * Any of these conditional tags that return true won't show the sidebar.
       * You can also specify your own custom function as long as it returns a boolean.
       * To use a function that accepts arguments, use an array instead of just the function name as a string.
       * Examples:
       * 'is_single'
       * 'is_archive'
       * ['is_page', 'about-me']
       * ['is_tax', ['flavor', 'mild']]
       * ['is_page_template', 'about.php']
       * ['is_post_type_archive', ['foo', 'bar', 'baz']]

These are instructions for how to use the function display_sidebar() to show or hide the sidebar.

What you mention in the code sample above is the content of ConditionalTagCheck. The reason of my post is how to override this via a function which forces the sidebar. For example like the sage_sidebar_on_special_page mentioned in the documentation. But I don’t know in which file and where in the file to write such a function.

I’m going to give up on this, because writing PHP functions isn’t a huge strength of mine, and because I’m still entirely unclear why you would want to manually write a function to show/hide the sidebar when Sage provides a simple and effective built-in way to achieve this.

Good luck.

Thanks for the help :smile:

The reason why we would want to write an overriding function is mentioned in the doc: “Unfortunately it’s not so easy to hide the sidebar for a large number of pages, but display it on just one.”

Does adding the filter here work for you? WP hooks and filters can be placed almost anywhere, save page templates. But anywhere in your theme’s functions.php files, or your plugin.

You want the sidebar to be displayed on ‘special-page’, correct?

Thank you Kalen, now I know a good place to put that code block: in the “lib” folder. Either in an existing Sage file (such as “extras.php”), or in a new file that I would add to the imports in “functions.php”.

1 Like