Dukeo » WordPress » Hide Sidebar on Pages: How To Do This In WordPress

Hide Sidebar on Pages: How To Do This In WordPress

Steven 4 responses WordPress

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.

If you enjoyed this article,
Get email updates

Join for Free »

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.