Dukeo » WordPress » Hide Sidebar on Search Pages: How To do This on WordPress

Hide Sidebar on Search Pages: How To do This on WordPress

Steven 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 search result page.

To hide your sidebar on your search result page, edit the search.php file from your theme (if your theme doesn’t include this file, edit the index.php file) and look for the following snippet of code:

<?php get_sidebar(); ?>

and replace it with:

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

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

If you enjoyed this article,
Get email updates

Join for Free »