Skip to main content

Widget is quite common and the most popular application commonly used on WordPress to keep track of various data, statistics, conversion rates, updates, and many more on the WordPress site. Most themes come with different kinds of widgets for the WordPress home page, landing page, login page, and many more. It helps you look your site more modern and up to the trend. In the upcoming article, let’s see how to show or hide widgets on Specific WordPress Pages.

Ways to Show or Hide Widgets on WordPress Specific Pages

There are two possible ways to display or hide widgets on your WordPress specific pages and they are

  • Show or Hide Widgets without Plugin
  • Show or Hide Widgets with Plugins

Show or Hide Widgets on Specific WordPress Pages Without Plugin

[1] From your WordPress dashboard, go to Appearance from the left panel.

[2] Choose Theme Editor/Editor from the Appearance menu.

Theme editor
[3] Under the Editor tab, go to the Theme files section and click on Function.php.

Show or Hide Widgets on Specific WordPress Pages
[4] Enter the following line of code in the function.php file.

//Hide widget in WordPress

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

Note: To find the Widget ID, go to the page where the widget is available and right-click on the page. Choose Inspect from the context menu. Now press Select the element icon (or) Ctrl + Shift + C on the keyboard. Click on the Widget to inspect the code. Here you can find the ID for the widget (<div id=”widget ID name“…..</div>).

Show or Hide Widgets on Specific WordPress Pages
//Show widget in WordPress

add_filter( 'widget_display_callback', 'show_widget_pages', 10, 3 );
function show_widget_pages( $instance, $widget, $args ) {
if ( $widget->id_base == 'xxxx' ) { // change 'xxxx' to widget name
if ( !is_page( 'yyyy' ) ) { // change 'yyyy' to page name
return false;
}
}
}
[5] Once the code is entered, click on Update Files to apply changes.

[6] Now you can successfully show or hide widgets on WordPress pages.

Related: How to Add WordPress Dark Mode [The Simplest Way]

Show or Hide Widgets on Specific WordPress Pages With Plugin

There are several plugins out there, in the WordPress plugin store that can be used to hide or show widgets on WordPress pages. Here, we are using the Widget Context plugin, so make sure to install and active the plugin by Plugins >> Add New >> Widget Context >> Install Now >> Activate.

Activate Widget context
[1] Go to your WordPress dashboard, go to Appearance and click on Widget from the menu.

Widgets
[2] Choose Widget Context as Show or Hide widget on selected.

[3] Then check the widgets, you wish to appear or disappear on your WordPress page or dashboard.

Show or Hide Widgets on Specific WordPress Pages
[4] Click on Save to apply the changes to your WordPress page.

[5] Now you have successfully shown or hidden widgets on the WordPress page.

Apart from Widget Context, there are several other plugins available to hide or show widgets and they are

Also, see How to Display Relative Dates in WordPress | Guide 2022

Conclusion

Hope this guide helps you find ways to show or hide Widgets on your WordPress site. Showing widget helps you keep track of several kinds of site data up to date. Hiding widgets may help you in speeding up the page and get a better conversion rate to your website. If you have any queries, let us know in the comments section below. For more WordPress guides and articles, explore the site.

Leave a Reply