Sometimes, you may want to display widgets only on certain pages of a site. If you’ve knowledge of PHP, you can show/hide widgets with just 2 lines of codes. The 1st line will have the PHP if else condition to detect the current page or term. If the condition you’ve specified in the if statement is true, then the code inside the if block must be executed.
The block must have the shortcode or code to display the required widget. It is the 2nd line of our code.
Showing or hiding widget is a great technique to display related content or targeted ads to the visitor. For example, if the current post is about cheap hosting plans, you can customize the code to display posts from the current category or an ad about Bluehost or Hostgator hosting package.
If you don’t know PHP, you can use the free plugin called Widget Logic to display or hide widgets.
How to show or hide widgets in WordPress?
WL is an amazing plugin. It eliminates the need to upgrade to premium themes that offer unlimited sidebar feature.
The plugin is easy to use and you can install it on your WordPress website through the WP-ADMIN interface.
To begin using the plugin, navigate to the Widget management page of your site. Then, click on any widget of your choice and drag it to the sidebar.
Now, click on the widget to customize it. On the options interface of the widget, you’ll see a text box with the title “Widget Logic”.
Inside the text box, you must place the WordPress conditional tags. Once you do so, click on the save button. That’s it!
WordPress will now display the widget only on the page or term you’ve entered in the text box.
For example, if you have entered is_single() tag in the text field, you’ll see widget only on the single pages/posts.
The plugin comes without any restrictions. It doesn’t have advertisements. You can configure as many widgets as you want with it.
Conclusion: If you want to hide or show WP widgets on certain posts, categories, tags or pages, you should install and use the widget logic plugin (download link). WP works like a charm. It is easy to configure. To enable or disable plugins on specific pages, use the WP plugin organizer.