Select Page

How To Display Different Sidebars For Different Pages

Page Template (Best for Single Pages)

If you only need to call a different sidebar on a single page and that page is totally unique, and there’s no need to have a plan for children of those pages, then a simple page template should do the trick. Just go to your parent theme, copy page.php (for classic themes) or page.html (for block themes) and paste it into the root directory of your child theme. You can also create page templates WYSIWYG style with blocks, but that’s for another time.

Rename page.php to include the slug of the one page you’re looking to change. If you want to be different, then rename page.php to be page-awesome-page.php. Open your freshly renamed file and search for the get_sidebar() function that is likely used in your page.php file and pass the name or ID of the sidebar you want into that function.

Conditional Statement (Best for Groups of Pages)

I had a situation in which I needed to manage a handful of different sidebars that all needed to be displayed on different pages, depending on what kind of page it is. For example, it it’s a page about bicycles, it needs to display the bicycle sidebar. If it’s a child page of the bicycle page, it also needs to display the bicycle sidebar. If it’s a page or child page about underwater basket weaving, it needs to display the sidebar for basket weaving. Else, just output a normal generic sidebar. This little function came in great handy to be placed in the child theme’s page.php:

if (is_page([ID OR SLUG]) || $post->post_parent == [postID] ) {
wp_nav_menu(array('menu' => 'menu_name'));

It should also be mentioned: the wp_nav_menu() function, can kinda take just a normal menu name or ID, but if you were like me and needed to stack a few if..elseif..elseif...elseif..else statements, I ended up seeing the same menu being outputted regardless of the ID or name passed into wp_nav_menu(). That was resolved when I passed the menu name into an array, like above. The first element of the array must be 'menu', and the second element is the name of whatever your menu is.

Check out more articles

Create a Custom API Endpoint in WordPress

Creating a custom endpoint in WordPress to check for plugin updates involves several steps. This process includes setting up a custom REST API endpoint, creating a function to handle requests to this endpoint, and ensuring that the response contains the necessary...

Deploy WordPress Updates from a Private Repository

To push code to a private repository and trigger a pending WordPress update badge, you need to follow a systematic approach involving version control, continuous integration/deployment, and the appropriate use of WordPress hooks and filters. Here’s a step-by-step...

How to Generate a Ranger Config File

ranger --copy-config=all This will copy all the default config files from /usr/local/lib so you can make edits without messing anything up. Huge shout out to for explaining this and so much more. Took me a...

First Open Source Contribution

Surprise! I genuinely did not plan on making my first ever open source contribution today. In fact, I didn't plan on a lot of things happening this week at all. I recently got an awesome opportunity to work on a site that is being hosted on a platform called Pantheon,...

How to Exclude Specific Posts and Pages from WP_QUERY

For the sake of having something to work with, let's suppose we've got the following query:In this query, inside the $args array, there's a special parameter that allows you to exclude specific posts and pages from the query. This parameter is called post__not_in and...

Configure SSH For Password-less Connections

Preamble I'm slightly embarrassed to admit this, but it was a long time before I figured out how amazing this little file is and how exactly to put it to good use. The file I'm talking about is the SSH config file. By default, when you first connect to a server via...

WordPress Site Stuck in Maintenance Mode

Plugin Error Code 500 During Update While I was updating a WordPress plugin locally, something happened on my local server to trigger a 500 error code as the plugin was updating. On the frontend, I refreshed the page and was greeted with "Briefly Unavailable for...

Creating a WordPress Plugin Downloader

How it Started I was recently tasked with the challenge of creating a WordPress theme generator. The idea being, instead of writing your style.css file from scratch, you'd be able to just answer a few simple questions about how you'd like your theme set up, and those...

Fix Audio on XFCE Chromebook

The Problem After moving from GalliumOS to Xubuntu, I noticed that playing YouTube videos on both Firefox and Chromium would result in decent playback for a few minutes, but suddenly the audio would turn into a solid beeping tone while the YouTube video displayed the...

Adjust Trackpad Sensitivity XFCE

xinput set-prop "Elan Touchpad" "Synaptics Finger" 1 1 1 What are the values 1 1 1? This sets the sensitivity as close to the original ChromeOS as possible. Larger numbers will decrease sensitivity of various aspects. I never looked into which individual value...

Looking for a place to host your next project or design?

Use this link to get your first 4 months of WP Engine for free: WP Engine – Plans (With 4 months free)