How to Hide Sidebar on Particular Page in WordPress?

Must Read

Four Things You Most Likely Didn’t Know About Guest Post Service

Guest Posting is a great way to raise awareness and build links. However, before starting a guest...

How Does Blogger Outreach Help Your Brand Grow?

Bloggers are eager to promote their content and engage their readers, so building relationships with them are...

How To Get Your Startup Noticed

Being an entrepreneur is always a learning experience. That's because the rules are constantly changing. The change...
Shrinivas
Hi, this is +Shrinivas. I am a freelance web developer and part time blogger having skills in WordPress, HTML/CSS, jQuery, PHP and CodeIgniter.

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">
<? } ?>
- Advertisement -

Latest News

Four Things You Most Likely Didn’t Know About Guest Post Service

Guest Posting is a great way to raise awareness and build links. However, before starting a guest...

How Does Blogger Outreach Help Your Brand Grow?

Bloggers are eager to promote their content and engage their readers, so building relationships with them are essential to growing your brand....

How To Get Your Startup Noticed

Being an entrepreneur is always a learning experience. That's because the rules are constantly changing. The change happens so subtly that you...

The Benefits of Treemapping for Data Analysis

Treemapping is a great tool for data analysis because it allows you to see the big picture and the details at the...

Tips for driving more traffic to your engineering blog

Over the last two decades, blogging has transformed from being a somewhat hobbyist pursuit to a fully-fledged sector of the internet that...

More Articles Like This

- Advertisement -