How to Hide Sidebar For Mobile Devices in WordPress

Photo of author

By Victor Ashiedu

Published

If you are reading this, you probably realized that having a sidebar on mobile devices is not necessary. This Itechguide teaches you how to hide the sidebar for mobile in WordPress.

Overview

For most WordPress themes, when you add sidebar widgets – primarily intended for larger screens – these sidebar widgets also display on mobile devices.

In the first instance, on a mobile device, a sidebar is no longer a “sidebar” but more of a “bottom bar”. Furthermore, on mobile devices, sidebars display after the main post – defeating the purpose of having them.

Moreover, having unnecessary sidebars on mobile devices may contribute to slow load times on these devices.

Some WordPress themes may have the option to customize sidebars by devices. If your theme offers this feature, please use it.

However, if your theme does not offer this option, use the steps in this guide to hide the sidebar on mobile devices.

Some of the steps in this guide require basic CSS skills. However, even though you do not know anything about CSS and stylesheets, I will walk you through it – step by step.
If you have a dev or staging site, I strongly recommend that you test these steps on your dev site before going live with it.

Step 1: Find The Sidebar DIV ID For Your Theme

Hiding sidebar on Mobile devices in WordPress essentially involves modifying the sidebar div with CSS. However, to modify the div with CSS, you need the div ID.

Please complete this task on a PC or Mac laptop or desktop – NOT on a mobile device.

Follow the steps below to find the div ID for the sidebar of the theme you use for your WordPress website:

  1. Open a post or page on Google Chrome or the new Microsoft Edge browser.
  2. Then, right-click anywhere on the sidebar and select Inspect.
How To Hide Sidebar For Mobile Devices In WordPress: step 1 - Find The Sidebar DIV ID For Your Theme
  1. The Inspect element will open some codes on the right of the page. This has an upper part (labelled 1 in the screenshot below). It also has a lower part (labelled 2 in the screenshot).

On the lower part, the Styles tab will be selected by default. To locate your sidebar div ID, look for an element with the word “sidebar”. Some themes may simply use “sidebar”. Others may use “sidebar-main” or “main-sidebar”.

Note this as it is your themes sidebar div ID. Mine is “sidebar”. Copy this as you will need it in the next step.

Step 2: Add this CSS Code to Your Site

The next step is to add this code to the “Additional CSS” section of your WordPress theme. This is the code that hides sidebars for mobile devices in WordPress.

I boldened the sidebar div ID for my theme. You need to change this value to the sidebar div ID for your theme. Note the dot (.) before the div ID.
@media (max-width: 768px)
 .sidebar {
     display: none;
 }

Follow the steps below to add the above CSS code to your theme:

  1. Sign in to your WordPress site as an administrator.
  2. Then, on the left pane, hover over Appearance and select Customise.
  1. When the Customise option opens, scroll down and click Additional CSS.
If your WordPress theme does not offer this option, open the theme options and find a place to add custom CSS.
  1. Finally, copy, paste and amend this code into one of the sections – then, on the top click Publish.
Remember to change .sidebar to the sidebar div ID from the last section.
@media (max-width: 768px)
 .sidebar {
     display: none;
 }
It may also be a good idea to add a comment describing what the code does and probably the date it was added. You can copy my comment and amend it as you wish. Whatever you do, DO not remove /* and */ – these are the codes that make whatever is in between a comment and not part of any CSS code.
/* Remove sidebar from mobile devices -3rd April 2021*/

Step 3: Clear Cache and Test

To be clear, the last section effectively hid the sidebar for mobile devices in WordPress. However, I decided to add this section because if you use a caching plugin or CDN, you will need to clear the cache for the changes to take effect immediately.

After clearing the cache in the caching plugin and/or CDN, open the website on a mobile device. If the change does not reflect immediately, use Incognito (Chrome) or InPrivate (Microsoft Edge).

Conclusion

I hope you were able to hide sidebar for mobile devices in your WordPress site with the steps in this guide.

I also hope you found the guide helpful and easy to understand? If you found the guide helpful, click Yes to “Was this post Helpful?” below.

You could also offer your feedback with the “Leave a comment” form found at the end of this page.

Finally, for more WordPress guides, visit our WordPress & Websites How-Tos page.

About the Author

Photo of author

Victor Ashiedu

Victor is the founder of InfoPress Media, publishers of Ilifeguides and Itechguides. With 20+ years of experience in IT infrastructure, his expertise spans Windows, Linux, and DevOps. Explore his contributions on Itechguides.com for insightful how-to guides and product reviews.

Related Articles

Get in Touch

We're committed to writing accurate content that informs and educates. To learn more, read our Content Writing Policy, Content Review Policy, Anti-plagiarism Policy, and About Us.

However, if this content does not meet your expectations, kindly reach out to us through one of the following means:

  1. Respond to "Was this page helpful?" above
  2. Leave a comment with the "Leave a Comment" form below
  3. Email us at [email protected] or via the Contact Us page.

5 thoughts on “How to Hide Sidebar For Mobile Devices in WordPress”

  1. It shouldn’t be a surprise. The code you have in the post for the @media query is not structured right. It IS missing brackets.

    Tomasz has it done the RIGHT way.

    Plus, using CSS to hide a big chunk of the page is a horrible idea. all the processing for it STILL happens – it’s just never shown to the user in the browser.

    Reply
    • It is a bit strange that you needed to include the extra braces. However, I am glad you made it work for you and thanks for staring!

      Reply

Leave a comment