How to Display/Hide Widgets Only on Select Pages

How to display a widget only on some pages and hide it on other pages? How do you restrict a widget from appearing on some pages of your WordPress website?

I have been getting this support question for almost 10 years now, and it surprises me how few WordPress users know that this is possible at all.

Why would anyone need to hide widgets on some pages?

There are situations when you don’t need a widget to appear on some pages. For example a museum website might have their Entry Prices and Working Schedule as two separate widgets in the sidebar, but also dedicated pages that contain this information.

So that you don’t repeat the same information both in the page’s content and as a widget, you can hide these widgets from the corresponding pages.

Or consider a university website with inner pages for each faculty. You can have different kinds of informative or call to action widgets created for each specific faculty.

The solution: widget visibility controls

Widget Options plugin banner

Enter: Widget Options by Phpbits Creative Studio.

Once you install and activate Widget Options, a free WordPress plugin, all your widgets (even custom widgets) will have new visibility options. See the area marked with a red border in the screenshot below:

Using the provided options you can easily control the appearance on widgets on PAGES. If you need to restrict the appearance of widgets on POSTS, then you will need to use the Logic tab, where you can use WordPress PHP conditionals.

This condition will display my widget only on the Post page with the post ID 85. You can use more complex conditionals if you feel like it.

Alternative Solution: custom sidebars

I have seen some WordPress users creating complete sidebars just for specific pages, and then calling via code these sidebars only in some custom page template files.

The theme’s template files end up looking like this:

To me this looks like overkill and is a method that is difficult to manage. It is much more logical to have a single sidebar defined for one area on the website, otherwise things can get out of control real fast.

What about Jetpack and the Widget Visibility module?

For a long time I have been recommending Jetpack, a plugin that comes with a few dozen different modules, including a Widget Visibility module. As the plugin raises some performance and data privacy issues, I now recommend a dedicated plugin that is focused on accomplishing just this one task.

Considering that Jetpack collects a ton of information off of your website, I can no longer blindly recommend the plugin left and right.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.