Hide Sidebar on Pages: How To Do This In WordPress

Steven4 responsesWordPress

Your WordPress blog sidebar is an essential element of your blog, however, on some occasions you might not want it to be displayed on your static pages.

To hide your sidebar on your static pages, edit the page.php file from your theme and look for the following snippet of code:

<?php get_sidebar(); ?>

and replace it with:

<?php if(!is_page()) {
  get_sidebar();
} ?>

You’re done! Your sidebar will be displayed on all your blog pages except on the static pages.

Learn how I made $33,543 online in the past 12 months.

Simply input your best email below to get started.

4 Comments

  1. thanks for share this tutorial.

  2. Jay

    Yay, it worked!

  3. Laura

    Worked like a charm. Many thanks!

    NOW I just need a trick to change the width of the main content area, depending on whether a sidebar is present. In other words, on the blog posts everything is laid out fine with the sidebar. But on the static pages, I need the content to stretch 100%.

    1. You’re welcome! I’m glad it helped.

Learn how I made $33,543 online in the past 12 months.

Simply input your best email below to get started.

No thanks, I have enough money