Sometime you mess with the scenario where it requires to remove the sidebar from wordpress especially on a particular page, personally I messed with such a situation while adding a portfolio in “My portfolio” page. Portfolio was not looking good along with the sidebar hence I decided to remove the sidebar only on “My portfolio” page and I am going to share that simple code with you. You might ask there comes a full width page template or no sidebar page template which can be used to hide the sidebar in WordPress but not many themes include such template and trick below comes handy there.
Removing Sidebar from Particular Page in WordPress
- login to your WordPress admin area
- Go to “Editor” under “Appearance” menu
- Click on Page Template (page.php) and copy the entire code to notepad so in case something goes wrong then you can revert back to original code
- Locate for <?php get_sidebar(); ?> and write the
<?php if (is_page('my-portfolio')) { ?> <? } else { ?>
php code above <?php get_sidebar(); ?>
- And write <? } ?> below <?php get_sidebar(); ?>
- So Now your code looks something like
<?php if (is_page('my-portfolio')) { ?> <? } else { ?> <?php get_sidebar(); ?> <? } ?>
- Finally click on “Update File” button
The code articulates wordpress to use the sidebar on the pages other than my-portfolio page, replace my-portfolio with your page name.
Now we have come up with the code that hides the sidebar but I also wanted to cover my portfolio in entire page. Though the sidebar was removed, the page content didn’t utilize that space so I just used is_page conditional statement for <div id=”primary”> line in Twenty Twelve WordPress theme. Here is the code which made the page content to fit in whole page after removing the sidebar.
<?php if (is_page('my-portfolio')) { ?> <? } else { ?> <div id="primary" class="site-content"> <? } ?>