Sidebar showing up on all page templates

Firstly, I realize there’s another forum discussion which is similar, however, I’m not modifying any loop behavior so resetting it does me no good. The default -custom.php template should operate and thus, this thread was born :wink:

I’m using a fairly vanilla version of Sage meaning I haven’t modified mostly any of the Sage core files or those in lib/ etc.

The one file I have modified is the lib/config.php file in order to HIDE the sidebar from rendering on certain page templates.

It does NOT show on 404 nor the front-page which is great, but all of my templates as well as the default template-custom.php still show the registered sidebar. The page I’m testing has the Sage custom template chosen as a test via the WordPress dropdown and inside of that is the following:

<?php
/**
 * Template Name: Custom Template
 */
?>

<?php while (have_posts()) : the_post(); ?>
  <?php get_template_part('templates/page', 'header'); ?>
  <?php get_template_part('templates/content', 'page'); ?>
<?php endwhile; ?>

Inside the lib/config.php for the sidebar conditional check starting at line #30 is the following:

/**
 * Define which pages shouldn't have the sidebar
 */
function display_sidebar() {
  static $display;

  if (!isset($display)) {
    $conditionalCheck = new Sage\ConditionalTagCheck(
      /**
       * 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 the following format:
       *
       * ['function_name', ['arg1', 'arg2']]
       *
       * Note: The second element must be an array even if there's only 1 argument.
       *
       * 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']]]
       *
       */
      [
        'is_404',
        'is_front_page',
        ['is_page_template', ['template-contact.php']],
        ['is_page_template', ['template-custom.php']]
      ]
    );

    $display = apply_filters('sage/display_sidebar', $conditionalCheck->result);
  }

Thank you for your assistance!

This recent fix from @swalkinshaw should get it working for you:

That did the trick! Thank you, Ben and Scott!

1 Like