MWDelaney, thank you for your suggestions. The CSS change you suggested was the spark that led to my solution.
The Sidebar
In setup.php
I removed my custom page template from the sidebar exceptions.
function display_sidebar() {
static $display;
isset($display) || $display = !in_array(true, [
// The sidebar will NOT be displayed if ANY of the following return true.
// @link https://codex.wordpress.org/Conditional_Tags
is_404(),
is_front_page(),
// is_page_template('template-custom.php'),
]);
return apply_filters('sage/display_sidebar', $display);
}
The Template
In base.php
I added the conditional for the page template check to the display_sidebar()
section so a specific class is added if my custom page template is active. My class mobile-sidebar-only
features the CSS that MWDelaney suggested.
<div class="wrap <?php echo (Setup\display_sidebar()) ? 'container' : 'container-full';?>" role="document">
<div class="content row">
<?php if (Setup\display_sidebar()) : ?>
<?php if ( is_page_template( 'template-custom.php' ) ) { ?>
<aside class="sidebar mobile-sidebar-only">
<?php } else { ?>
<aside class="sidebar">
<?php } ?>
<?php include Wrapper\sidebar_path(); ?>
</aside><!-- /.sidebar -->
<?php endif; ?>
<main class="main">
<?php include Wrapper\template_path(); ?>
</main><!-- /.main -->
</div><!-- /.content -->
</div><!-- /.wrap -->
In the event that multiple page templates need to be included in the conditional, I can change it to an array:
<?php if ( is_page_template( array( 'template-custom.php', 'template-this-one.php', 'template-that-one.php' ) ) ) { ?>
The CSS
In _grid.scss
, the flexbox column widths for both the sidebar
and main
sections are generated using the make-col
mixin. I updated the CSS to define the column widths differently at the md
breakpoint if my custom page template class is active. I renamed the .template-custom
class that hides the sidebar at the md
breakpoint to .mobile-sidebar-only
in the event that another custom page template needs to have this functionality. I wouldn’t want to create specific classes for each instance if it isn’t absolutely necessary.
.main {
margin-top: 2.5rem;
@include make-col-ready();
@include media-breakpoint-up(md) {
@include make-col($main-md-columns);
.sidebar-primary & {
@include make-col($main-md-columns - $sidebar-md-columns);
}
.sidebar-primary.page-template-template-custom & {
@include make-col($main-md-columns);
}
}
}
.sidebar {
@include make-col-ready();
@include media-breakpoint-up(md) {
@include make-col($sidebar-md-columns);
}
@include media-breakpoint-up(lg) {
padding-right: 80px;
}
&.mobile-sidebar-only {
@extend .d-md-none, .d-lg-none, .d-xl-none;
}
}
Thank you again to both Simeon and MWDelaney for your help in creating a solution!