hide widgets on certain pages in wordpress

hide widgets on certain pages in wordpress

There are many ways to hide widgets from certain page in wordpress. Here we will give code sample and information about wordpress plugin which will be helpful to wordpress users to manage widgets in smarter way.

hide widgets on certain pages

There is manual and old way of hiding widgets on certain pages which is adding code in theme. You can get your page name or page id and use following code.


add_filter( 'widget_display_callback', 'hide_widget_pages', 10, 3 );
function hide_widget_pages( $instance, $widget, $args ) {
if ( $widget->id_base == 'pages' ) { // change 'pages' to widget name
if ( !is_page( 'contact' ) ) {    // change page name
return false;
}
}
}

You need to copy and paste above code into functions.php file (themes folder).

Now we will tell you about automatic and smart way. There is very nice and good wordpress plugin which will give you more options in widget so you can control your widget more smartly.

Display Widgets

Change your sidebar content for different pages, categories, custom taxonomies, and WPML languages. Avoid creating multiple sidebars and duplicating widgets by adding check boxes to each widget in the admin (as long as it is written in the WordPress version 2.8 format) which will either show or hide the widgets on every site page. Great for avoiding extra coding and keeping your sidebars clean.

By default, ‘Hide on checked pages’ is selected with no boxes checked, so all current widgets will continue to display on all pages.

hide widgets on certain pages in wordpress
hide widgets on certain pages in wordpress

Above is screen shot of widget admin section. There are many options you can find for every widget. I found this plugin is very helpful to me.

There is option of hide widget for checked pages. You can check certain pages for hiding widgets. This is code free solution which i recommend for all wordpress users.

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.